warn of action clashes
This commit is contained in:
parent
6a6bb1636a
commit
6cb7f14407
19
src/Updux.js
19
src/Updux.js
@ -14,10 +14,21 @@ export class Updux {
|
|||||||
this.#localInitial = config.initial ?? {};
|
this.#localInitial = config.initial ?? {};
|
||||||
this.#subduxes = config.subduxes ?? {};
|
this.#subduxes = config.subduxes ?? {};
|
||||||
|
|
||||||
this.#actions = R.mergeAll([
|
this.#actions = { ...config.actions };
|
||||||
config.actions ?? {},
|
Object.entries(this.#subduxes).forEach( ([slice,sub]) => this.#addSubduxActions(slice,sub) )
|
||||||
...Object.values(this.#subduxes).map(R.prop('actions')),
|
}
|
||||||
]);
|
|
||||||
|
#addSubduxActions(_slice, subdux) {
|
||||||
|
if( ! subdux.actions ) return;
|
||||||
|
// TODO action 'blah' defined multiple times: <where>
|
||||||
|
Object.entries( subdux.actions ).forEach( ([action,gen]) => {
|
||||||
|
if( this.#actions[action] ) {
|
||||||
|
if( this.#actions[action] === gen ) return;
|
||||||
|
throw new Error(`action '${action}' already defined`);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.#actions[action] = gen;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get actions() {
|
get actions() {
|
||||||
|
@ -51,3 +51,19 @@ test('subduxes actions', () => {
|
|||||||
expect(foo.actions).toHaveProperty('foo');
|
expect(foo.actions).toHaveProperty('foo');
|
||||||
expect(foo.actions).toHaveProperty('bar');
|
expect(foo.actions).toHaveProperty('bar');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('throw if double action', () => {
|
||||||
|
expect( () => new Updux({
|
||||||
|
actions: {
|
||||||
|
foo: action('foo'),
|
||||||
|
},
|
||||||
|
subduxes: {
|
||||||
|
beta: {
|
||||||
|
actions: {
|
||||||
|
foo: action('foo'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}) ).toThrow(/action 'foo' already defined/);
|
||||||
|
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user