initial state and splats
This commit is contained in:
parent
51421c1052
commit
3e6d2dae55
11
src/Updux.js
11
src/Updux.js
@ -24,7 +24,7 @@ export class Updux {
|
|||||||
|
|
||||||
constructor(config = {}) {
|
constructor(config = {}) {
|
||||||
this.#config = config;
|
this.#config = config;
|
||||||
this.#localInitial = config.initial ?? {};
|
this.#localInitial = config.initial;
|
||||||
this.#subduxes = config.subduxes ?? {};
|
this.#subduxes = config.subduxes ?? {};
|
||||||
|
|
||||||
this.#actions = R.mapValues(config.actions ?? {}, (arg, name) =>
|
this.#actions = R.mapValues(config.actions ?? {}, (arg, name) =>
|
||||||
@ -73,11 +73,16 @@ export class Updux {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get initial() {
|
get initial() {
|
||||||
if (Object.keys(this.#subduxes).length === 0) return this.#localInitial;
|
if (Object.keys(this.#subduxes).length === 0) return this.#localInitial ?? {};
|
||||||
|
|
||||||
|
if( this.#subduxes['*'] ) {
|
||||||
|
if( this.#localInitial ) return this.#localInitial;
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
return Object.assign(
|
return Object.assign(
|
||||||
{},
|
{},
|
||||||
this.#localInitial,
|
this.#localInitial ?? {},
|
||||||
R.mapValues(this.#subduxes, ({ initial }) => initial),
|
R.mapValues(this.#subduxes, ({ initial }) => initial),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -25,3 +25,20 @@ test('initial value', () => {
|
|||||||
bar: 123,
|
bar: 123,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test( "splat initial", async () => {
|
||||||
|
const bar = new Updux({
|
||||||
|
initial: { id: 0 },
|
||||||
|
});
|
||||||
|
|
||||||
|
const foo = new Updux({
|
||||||
|
subduxes: { '*': bar },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(foo.initial).toEqual([]);
|
||||||
|
|
||||||
|
expect( new Updux({
|
||||||
|
initial: 'overriden',
|
||||||
|
subduxes: { '*': bar },
|
||||||
|
}).initial ).toEqual('overriden');
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user