prettier
This commit is contained in:
parent
fbe624a14c
commit
16397ce3ee
24
src/Updux.js
24
src/Updux.js
@ -76,10 +76,11 @@ export class Updux {
|
||||
}
|
||||
|
||||
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;
|
||||
if (this.#subduxes['*']) {
|
||||
if (this.#localInitial) return this.#localInitial;
|
||||
return [];
|
||||
}
|
||||
|
||||
@ -183,19 +184,18 @@ export class Updux {
|
||||
this.#effects = [...this.#effects, [action, effect]];
|
||||
}
|
||||
|
||||
addReaction( reaction ) {
|
||||
this.#localReactions = [ ...this.#localReactions, reaction ]
|
||||
addReaction(reaction) {
|
||||
this.#localReactions = [...this.#localReactions, reaction];
|
||||
}
|
||||
|
||||
subscribeTo(store, subscription) {
|
||||
const localStore = augmentMiddlewareApi(
|
||||
{
|
||||
...store,
|
||||
subscribe: (subscriber) =>
|
||||
this.subscribeTo(store, subscriber), // TODO not sure
|
||||
subscribe: (subscriber) => this.subscribeTo(store, subscriber), // TODO not sure
|
||||
},
|
||||
this.actions,
|
||||
this.selectors
|
||||
this.selectors,
|
||||
);
|
||||
|
||||
const subscriber = subscription(localStore);
|
||||
@ -221,7 +221,7 @@ export class Updux {
|
||||
|
||||
subscribeAll(store) {
|
||||
let results = this.#localReactions.map((sub) =>
|
||||
this.subscribeTo(store, sub)
|
||||
this.subscribeTo(store, sub),
|
||||
);
|
||||
|
||||
for (const subdux in this.#subduxes) {
|
||||
@ -237,10 +237,10 @@ export class Updux {
|
||||
return {
|
||||
unsub: () => results.forEach(({ unsub }) => unsub()),
|
||||
subscriberMemoized: () =>
|
||||
results.forEach(({ subscriberMemoized}) => subscriberMemoized()),
|
||||
subscriber: () =>
|
||||
results.forEach(({ subscriber }) => subscriber()
|
||||
results.forEach(({ subscriberMemoized }) =>
|
||||
subscriberMemoized(),
|
||||
),
|
||||
subscriber: () => results.forEach(({ subscriber }) => subscriber()),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ test('initial value', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test( "splat initial", async () => {
|
||||
test('splat initial', async () => {
|
||||
const bar = new Updux({
|
||||
initial: { id: 0 },
|
||||
});
|
||||
@ -37,8 +37,10 @@ test( "splat initial", async () => {
|
||||
|
||||
expect(foo.initial).toEqual([]);
|
||||
|
||||
expect( new Updux({
|
||||
expect(
|
||||
new Updux({
|
||||
initial: 'overriden',
|
||||
subduxes: { '*': bar },
|
||||
}).initial ).toEqual('overriden');
|
||||
}).initial,
|
||||
).toEqual('overriden');
|
||||
});
|
||||
|
@ -30,7 +30,7 @@ test('subduxes reactions', async () => {
|
||||
subduxes: {
|
||||
a: new Updux({
|
||||
initial: 1,
|
||||
reactions: [() => state => spyA(state)],
|
||||
reactions: [() => (state) => spyA(state)],
|
||||
actions: { inc: null },
|
||||
mutations: {
|
||||
inc: () => (state) => state + 1,
|
||||
@ -45,6 +45,6 @@ test('subduxes reactions', async () => {
|
||||
store.dispatch.inc();
|
||||
|
||||
expect(spyA).toHaveBeenCalledTimes(2);
|
||||
expect(spyA).toHaveBeenCalledWith(3)
|
||||
expect(spyA).toHaveBeenCalledWith(3);
|
||||
expect(spyB).toHaveBeenCalledOnce(); // the original inc initialized the state
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user