tyding up
This commit is contained in:
parent
6168720c47
commit
1983e2ec07
@ -1,11 +1,13 @@
|
||||
{
|
||||
"name": "updux",
|
||||
"types": "dist",
|
||||
"version": "0.0.1",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/jest": "^24.0.19",
|
||||
"@types/lodash": "^4.14.144",
|
||||
"dtslint": "^0.9.8",
|
||||
"lodash": "^4.17.15",
|
||||
"redux": "^4.0.4",
|
||||
"ts-jest": "^24.1.0",
|
||||
@ -19,5 +21,8 @@
|
||||
"babel-jest": "^24.9.0",
|
||||
"jest": "^24.9.0",
|
||||
"updeep": "^1.2.0"
|
||||
}
|
||||
},
|
||||
"tsd": {
|
||||
"directory": "test-d"
|
||||
}
|
||||
}
|
||||
|
@ -1,30 +1,21 @@
|
||||
import fp from 'lodash/fp';
|
||||
import { ActionEffects, ActionCreator, ActionCreators, ActionMutations } from '../types';
|
||||
|
||||
function actionFor(type) {
|
||||
return (payload = null, meta = null) => {
|
||||
return fp.pickBy(v => v !== null)({type, payload, meta});
|
||||
};
|
||||
function actionFor(type: string) {
|
||||
return ( (payload = undefined, meta = undefined) =>
|
||||
fp.pickBy(v => v !== null)({type, payload, meta})
|
||||
) as ActionCreator;
|
||||
}
|
||||
|
||||
export default function buildActions(
|
||||
mutations = {},
|
||||
effects = {},
|
||||
subActions = {},
|
||||
mutations : ActionMutations = {},
|
||||
effects : ActionEffects = {},
|
||||
subActions : ActionCreators = {},
|
||||
) {
|
||||
|
||||
let actions = { ...subActions };
|
||||
return { ...subActions,
|
||||
...fp.fromPairs([ ...Object.keys(mutations), ...Object.keys(effects) ]
|
||||
.map( type => [ type, actionFor(type) ]))
|
||||
};
|
||||
|
||||
Object.keys(mutations).forEach(type => {
|
||||
if (!actions[type]) {
|
||||
actions[type] = actionFor(type);
|
||||
}
|
||||
});
|
||||
|
||||
Object.keys(effects).forEach(type => {
|
||||
if (!actions[type]) {
|
||||
actions[type] = actionFor(type);
|
||||
}
|
||||
});
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
6
src/buildInitial/index.test-d.ts
Normal file
6
src/buildInitial/index.test-d.ts
Normal file
@ -0,0 +1,6 @@
|
||||
// TypeScript Version: 3.4
|
||||
|
||||
import buildInitial from '.';
|
||||
|
||||
// $ExpectType any
|
||||
const x = buildInitial();
|
28
src/index.ts
28
src/index.ts
@ -3,32 +3,6 @@ import u from 'updeep';
|
||||
|
||||
import Updux from './updux';
|
||||
|
||||
|
||||
|
||||
|
||||
function updux(config) {
|
||||
export default function updux(config) {
|
||||
return new Updux(config);
|
||||
// const actions = buildActions(
|
||||
// config.mutations,
|
||||
// config.effects,
|
||||
// fp.flatten( ( config.subduxes||{}).map( ({ actions }) => actions ) )
|
||||
// );
|
||||
|
||||
// const initial = buildInitial(config);
|
||||
|
||||
// const mutations = buildMutations(config.mutations,config.subduxes);
|
||||
|
||||
|
||||
|
||||
// return {
|
||||
// reducer,
|
||||
// upreducer,
|
||||
// middleware,
|
||||
// createStore,
|
||||
// actions: ( actions as any ),
|
||||
// mutations,
|
||||
// initial,
|
||||
// };
|
||||
}
|
||||
|
||||
export default updux;
|
||||
|
16
src/types.ts
16
src/types.ts
@ -5,3 +5,19 @@ export type Mutation = (payload: any, action: any) => (state:any) => any;
|
||||
|
||||
export type Mutations = Dictionary<Mutation>;
|
||||
|
||||
export type ActionMutations = Dictionary<Mutation>;
|
||||
|
||||
export type Effect = (api:any) => (next: Function) => (action: any) => any;
|
||||
|
||||
export type ActionEffects = Dictionary<Effect>;
|
||||
|
||||
export type Action<T = string, P = any, M = any> = {
|
||||
type: T,
|
||||
payload: P,
|
||||
meta: M,
|
||||
}
|
||||
|
||||
export type ActionCreator = <P,M>(payload?: P, meta?: M ) => Action<string,P,M>;
|
||||
|
||||
export type ActionCreators = Dictionary<ActionCreator>;
|
||||
|
||||
|
@ -3,7 +3,7 @@ import buildActions from './buildActions';
|
||||
import buildInitial from './buildInitial';
|
||||
import buildMutations from './buildMutations';
|
||||
|
||||
import { Dictionary, Mutation } from './types';
|
||||
import { Dictionary, Mutation, ActionCreators } from './types';
|
||||
import buildCreateStore from './buildCreateStore';
|
||||
import buildMiddleware from './buildMiddleware';
|
||||
import buildUpreducer from './buildUpreducer';
|
||||
@ -18,7 +18,7 @@ type UpduxConfig = {
|
||||
};
|
||||
|
||||
export class Updux {
|
||||
actions: any;
|
||||
actions: ActionCreators;
|
||||
|
||||
subduxes: Dictionary<Updux>;
|
||||
|
||||
|
@ -4,19 +4,19 @@
|
||||
"incremental": true, /* Enable incremental compilation */
|
||||
"target": "ES2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
"lib": [ "dom", "es2017" ], /* Specify library files to be included in the compilation. */
|
||||
"lib": [ "dom", "es2019" ], /* Specify library files to be included in the compilation. */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
"declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
"declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
"sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
"outDir": "./dist", /* Redirect output structure to the directory. */
|
||||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "composite": true, /* Enable project compilation */
|
||||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
"removeComments": true, /* Do not emit comments to output. */
|
||||
// "noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
|
Loading…
Reference in New Issue
Block a user