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.#subduxes = config.subduxes ?? {};
|
||||
|
||||
this.#actions = R.mergeAll([
|
||||
config.actions ?? {},
|
||||
...Object.values(this.#subduxes).map(R.prop('actions')),
|
||||
]);
|
||||
this.#actions = { ...config.actions };
|
||||
Object.entries(this.#subduxes).forEach( ([slice,sub]) => this.#addSubduxActions(slice,sub) )
|
||||
}
|
||||
|
||||
#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() {
|
||||
|
@ -51,3 +51,19 @@ test('subduxes actions', () => {
|
||||
expect(foo.actions).toHaveProperty('foo');
|
||||
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