-
Notifications
You must be signed in to change notification settings - Fork 14
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
0 parents
commit 60bc246
Showing
8 changed files
with
1,835 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,105 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"env": { | ||
"browser": true, | ||
"jest": true | ||
}, | ||
"rules": { | ||
"generator-star-spacing": [ | ||
0 | ||
], | ||
"consistent-return": [ | ||
0 | ||
], | ||
"radix": [ | ||
1 | ||
], | ||
"no-unused-vars": 2, | ||
"global-require": [ | ||
0 | ||
], | ||
"import/prefer-default-export": [ | ||
0 | ||
], | ||
"no-else-return": [ | ||
0 | ||
], | ||
"no-restricted-syntax": [ | ||
0 | ||
], | ||
"no-use-before-define": [ | ||
0 | ||
], | ||
"no-nested-ternary": [ | ||
0 | ||
], | ||
"arrow-body-style": [ | ||
0 | ||
], | ||
"import/extensions": [ | ||
0 | ||
], | ||
"no-bitwise": [ | ||
0 | ||
], | ||
"no-cond-assign": [ | ||
0 | ||
], | ||
"import/no-unresolved": [ | ||
0 | ||
], | ||
"require-yield": [ | ||
1 | ||
], | ||
"no-param-reassign": [ | ||
0 | ||
], | ||
"no-shadow": [ | ||
0 | ||
], | ||
"no-underscore-dangle": [ | ||
0 | ||
], | ||
"spaced-comment": [ | ||
0 | ||
], | ||
"indent": [ | ||
0 | ||
], | ||
"quotes": [ | ||
0 | ||
], | ||
"func-names": [ | ||
0 | ||
], | ||
"arrow-parens": [ | ||
0 | ||
], | ||
"space-before-function-paren": [ | ||
0 | ||
], | ||
"no-useless-escape": [ | ||
0 | ||
], | ||
"object-curly-newline": [ | ||
0 | ||
], | ||
"function-paren-newline": [ | ||
0 | ||
], | ||
"class-methods-use-this": [ | ||
0 | ||
], | ||
"no-new": [ | ||
0 | ||
], | ||
"no-console": [ | ||
1 | ||
] | ||
}, | ||
"parserOptions": { | ||
"ecmaFeatures": { | ||
"experimentalObjectRestSpread": 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 @@ | ||
node_modules |
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,5 @@ | ||
{ | ||
"printWidth": 100, | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} |
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,4 @@ | ||
|
||
export const SEP = '/'; | ||
|
||
export const GeneratorConstructor = function* generator() {}.constructor; |
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,55 @@ | ||
|
||
import { SEP } from './const' | ||
|
||
export const takeLatest = (target, key, descriptor) => { | ||
let _descriptor = descriptor; | ||
if (_descriptor === undefined) { | ||
_descriptor = Object.getOwnPropertyDescriptor(target, key); | ||
} | ||
target.__takelatest = [...(target.__takelatest || []), key] | ||
return _descriptor; | ||
}; | ||
|
||
export const takeEvery = (target, key, descriptor) => { | ||
let _descriptor = descriptor; | ||
if (_descriptor === undefined) { | ||
_descriptor = Object.getOwnPropertyDescriptor(target, key); | ||
} | ||
target.__takeEvery = [...(target.__takeEvery || []), key] | ||
return _descriptor; | ||
}; | ||
|
||
export const throttle = (target, key, descriptor) => { | ||
let _descriptor = descriptor; | ||
if (_descriptor === undefined) { | ||
_descriptor = Object.getOwnPropertyDescriptor(target, key); | ||
} | ||
target.__throttle = [...(target.__throttle || []), key] | ||
return _descriptor; | ||
}; | ||
|
||
export const action = (ModelClass) => { | ||
const proto = ModelClass.prototype; | ||
const actions = Object.getOwnPropertyNames(proto); | ||
|
||
function prefix(type) { | ||
return `${ModelClass.name}${SEP}${type}`; | ||
} | ||
|
||
function createAction(method) { | ||
Reflect.set(ModelClass, method, payload => { | ||
return ({ type: prefix(method), payload }) | ||
}); | ||
} | ||
|
||
for (let index = 0; index < actions.length; index++) { | ||
const prop = actions[index]; | ||
if (prop === 'constructor') continue; | ||
if (typeof proto[prop] === "function") { | ||
createAction(prop); | ||
continue | ||
} | ||
} | ||
|
||
return ModelClass | ||
} |
Oops, something went wrong.