This commit is contained in:
Yanick Champoux 2022-08-30 14:16:29 -04:00
parent fbe624a14c
commit 16397ce3ee
4 changed files with 24 additions and 22 deletions

View File

@ -24,15 +24,15 @@ tasks:
lint:delta:
cmds:
- task: 'lint:prettier:delta'
- task: 'lint:eslint:delta'
- task: 'lint:prettier:delta'
- task: 'lint:eslint:delta'
lint:prettier:delta:
vars:
FILES:
sh: git diff-ls --diff-filter=d {{.ROOT_BRANCH | default "main"}} | grep -v .vitebook
cmds:
- npx prettier --check {{.FILES | catLines }}
- npx prettier --check {{.FILES | catLines }}
lint:eslint:delta:
vars:

View File

@ -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()),
};
}
}

View File

@ -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({
initial: 'overriden',
subduxes: { '*': bar },
}).initial ).toEqual('overriden');
expect(
new Updux({
initial: 'overriden',
subduxes: { '*': bar },
}).initial,
).toEqual('overriden');
});

View File

@ -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
});