Skip to content

Commit

Permalink
feat: first-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
taixw2 committed Jan 8, 2020
0 parents commit 60bc246
Show file tree
Hide file tree
Showing 8 changed files with 1,835 additions and 0 deletions.
105 changes: 105 additions & 0 deletions .eslintrc
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
}
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"printWidth": 100,
"singleQuote": true,
"trailingComma": "all"
}
4 changes: 4 additions & 0 deletions const.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

export const SEP = '/';

export const GeneratorConstructor = function* generator() {}.constructor;
55 changes: 55 additions & 0 deletions decorators.js
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
}
Loading

0 comments on commit 60bc246

Please sign in to comment.