-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Darmikon
committed
Jan 15, 2017
0 parents
commit 0c4e078
Showing
7 changed files
with
232 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"presets": [ | ||
"latest", | ||
"stage-0" | ||
], | ||
"compact": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Created by .ignore support plugin (hsz.mobi) | ||
### JetBrains template | ||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm | ||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 | ||
|
||
# User-specific stuff: | ||
.idea/* | ||
|
||
## File-based project format: | ||
*.iws | ||
|
||
## Plugin-specific files: | ||
|
||
# IntelliJ | ||
/out/ | ||
|
||
# mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
# JIRA plugin | ||
atlassian-ide-plugin.xml | ||
|
||
# Crashlytics plugin (for Android Studio and IntelliJ) | ||
com_crashlytics_export_strings.xml | ||
crashlytics.properties | ||
crashlytics-build.properties | ||
fabric.properties | ||
### Node template | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# ducks-helpers | ||
Utils for ducks in redux | ||
|
||
Api is not stable. You can use some ideas in your projects. | ||
`constants()` - generates constants, however if `~` sign presents at the beginning then extra sufixes will be generated | ||
|
||
``` | ||
import {constants} from 'ducks-helpers' | ||
``` | ||
|
||
``` | ||
export const TYPE = constants('module-name/namespace', [ | ||
'~GET_NOTE', //it will create GET_NOTE, GET_NOTE_LOADING, ... | ||
'NORMAL_ACTION' //it will create only itself | ||
]) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { createAction } from 'redux-actions'; | ||
|
||
/* --------------------------example-------------------------------- | ||
export const TYPE = constants('module-name/namespace', [ | ||
'~GET_NOTE', //it will create GET_NOTE, GET_NOTE_LOADING, ... | ||
'NORMAL_ACTION' //it will create only itself | ||
]) | ||
------------------------------------------------------------------*/ | ||
|
||
export function constants(namespace = '', types){ | ||
const _SUFFIXES = [ | ||
'LOADING', | ||
'PENDING', | ||
'SUCCESS', | ||
'ERROR', | ||
'FAILED', | ||
'CANCELED' | ||
] | ||
|
||
if(arguments.length === 1 || Array.isArray(namespace)){ | ||
types = namespace; | ||
namespace = ''; | ||
} | ||
|
||
if(!Array.isArray(types)){ | ||
throw 'types should be an array'; | ||
} | ||
|
||
return types.reduce((obj,name)=>{ | ||
if(name.indexOf('~') === 0){ | ||
let type = name.slice(1); | ||
|
||
obj[type] = (namespace ? `${namespace}/` : '') + `${type}`; | ||
|
||
_SUFFIXES.forEach(suf=>{ | ||
obj[type + '_' + suf] = (namespace ? `${namespace}/` : '') + `${type}_${suf}` | ||
}) | ||
}else{ | ||
obj[name] = name; | ||
} | ||
|
||
return obj; | ||
},{}) | ||
} | ||
|
||
//HELPERS | ||
export function loading(state, action){ | ||
return { ...state, error: null, loading: true } | ||
} | ||
|
||
export function success(state, action){ | ||
return { ...state, payload: action.payload, error: null, loading: false } | ||
} | ||
|
||
export function error(state, action){ | ||
let error = action.payload && action.payload | ||
return { ...state, payload: [], error, loading: false } | ||
} | ||
|
||
|
||
function camelize(str) { | ||
return str.toLowerCase() | ||
.split('_') | ||
.reduce((output,word)=>{ | ||
if(!output){ | ||
output = word; | ||
}else{ | ||
output += word.charAt(0).toUpperCase() + word.slice(1); | ||
} | ||
|
||
return output; | ||
}); | ||
} | ||
|
||
function isObject(obj) { | ||
return obj === Object(obj); | ||
} | ||
|
||
export function actions(TYPES){ | ||
if(!isObject(TYPES)){ | ||
throw 'TYPES should be an object' | ||
} | ||
|
||
return Object.keys(TYPES).reduce((actions,TYPE)=>{ | ||
actions[camelize(TYPE)] = createAction(TYPE); | ||
|
||
return actions; | ||
},{}) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "ducks-helpers", | ||
"version": "1.0.0", | ||
"description": "Utils for redux", | ||
"main": "lib/index.js", | ||
"files": [ | ||
"lib" | ||
], | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"build": "babel index.js --out-dir lib" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Darmikon/ducks-helpers.git" | ||
}, | ||
"keywords": [ | ||
"redux", | ||
"react" | ||
], | ||
"author": "Roman Yudin", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/Darmikon/ducks-helpers/issues" | ||
}, | ||
"homepage": "https://github.com/Darmikon/ducks-helpers#readme", | ||
"devDependencies": { | ||
"babel-cli": "^6.18.0", | ||
"babel-preset-es2015": "^6.18.0", | ||
"babel-preset-latest": "^6.16.0", | ||
"babel-preset-stage-0": "^6.16.0" | ||
}, | ||
"dependencies": { | ||
"redux-actions": "^1.2.0" | ||
} | ||
} |