wip
This commit is contained in:
parent
1825e8d269
commit
f744616cb2
@ -7,7 +7,9 @@ function subSelectors([slice, subdux]: [string, Updux]): [ string, Selector ][]
|
||||
if (!selectors) return [];
|
||||
|
||||
return Object.entries(
|
||||
fp.mapValues(selector => (state:any) => (selector as any)(state[slice]))(selectors)
|
||||
fp.mapValues(selector => (state: any) =>
|
||||
(selector as any)(state[slice])
|
||||
)(selectors)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ test('basic selectors', () => {
|
||||
selectors: {
|
||||
bogeys: ({ bogeys }: any) => bogeys,
|
||||
},
|
||||
} as any);
|
||||
});
|
||||
|
||||
const state = {
|
||||
bogeys: {
|
||||
@ -21,8 +21,6 @@ test('basic selectors', () => {
|
||||
}
|
||||
};
|
||||
|
||||
console.log(updux.selectors);
|
||||
|
||||
expect( updux.selectors.bogeys(state) ).toEqual( { foo:1, bar :2 } );
|
||||
expect( (updux.selectors.bogey(state) as any)('foo')).toEqual(1);
|
||||
|
||||
|
@ -98,6 +98,8 @@ export type UpduxConfig<S = any> = {
|
||||
[type: string]: ActionCreator;
|
||||
};
|
||||
|
||||
selectors?: Dictionary<Selector>;
|
||||
|
||||
/**
|
||||
* Object mapping actions to the associated state mutation.
|
||||
*
|
||||
|
11
src/updux.ts
11
src/updux.ts
@ -46,7 +46,7 @@ export type Dux<S> = Pick<
|
||||
>;
|
||||
|
||||
export class Updux<S = any> {
|
||||
subduxes: Dictionary<Updux>;
|
||||
subduxes: Dictionary<Updux> = {};
|
||||
|
||||
private local_selectors: Dictionary<Selector<S>> = {};
|
||||
|
||||
@ -69,9 +69,11 @@ export class Updux<S = any> {
|
||||
const selectors = fp.getOr( {}, 'selectors', config ) as Dictionary<Selector>;
|
||||
Object.entries(selectors).forEach( ([name,sel]: [string,Function]) => this.addSelector(name,sel as Selector) );
|
||||
|
||||
this.subduxes = fp.mapValues((value: UpduxConfig | Updux) =>
|
||||
fp.isPlainObject(value) ? new Updux(value) : value
|
||||
)(fp.getOr({}, "subduxes", config)) as Dictionary<Updux>;
|
||||
Object.entries( fp.mapValues((value: UpduxConfig | Updux) =>
|
||||
fp.isPlainObject(value) ? new Updux(value as any) : value
|
||||
)(fp.getOr({}, "subduxes", config))).forEach(
|
||||
([slice,sub]) => this.subduxes[slice] = sub as any
|
||||
);
|
||||
|
||||
const actions = fp.getOr({}, "actions", config);
|
||||
Object.entries(actions).forEach(([type, payload]: [string, any]): any =>
|
||||
@ -104,7 +106,6 @@ export class Updux<S = any> {
|
||||
}
|
||||
|
||||
get actions(): Dictionary<ActionCreator> {
|
||||
|
||||
return buildActions([
|
||||
...(Object.entries(this.localActions) as any),
|
||||
...(fp.flatten(
|
||||
|
Loading…
Reference in New Issue
Block a user