Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: neurosnap/starfx
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 30b2a5594d1c45b3daf64b78d9feb27f35c975bb
Choose a base ref
..
head repository: neurosnap/starfx
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1b6fdfb9a65af606778219e60bfd25286df17312
Choose a head ref
Showing with 19 additions and 20 deletions.
  1. +14 −0 queue.ts
  2. +3 −5 redux/fx.ts
  3. +2 −15 store/fx.ts
14 changes: 14 additions & 0 deletions queue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createQueue } from "./deps.ts";

export function createFilterQueue<T, TClose>(predicate: (v: T) => boolean) {
const queue = createQueue<T, TClose>();

return {
...queue,
add(value: T) {
if (predicate(value)) {
queue.add(value);
}
},
};
}
8 changes: 3 additions & 5 deletions redux/fx.ts
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@ import {
import { call } from "../fx/mod.ts";
import { ActionPattern, matcher } from "../matcher.ts";
import type { ActionWPayload, AnyAction } from "../types.ts";

import type { StoreLike } from "./types.ts";

export const ActionContext = createContext<Signal<Action, void>>(
@@ -63,7 +62,7 @@ export function* select<S, R>(selectorFn: (s: S) => R) {
return selectorFn(store.getState() as S);
}

export function useActions(pattern: ActionPattern): Stream<AnyAction, void> {
function useActions(pattern: ActionPattern): Stream<AnyAction, void> {
return {
*subscribe() {
const actions = yield* ActionContext;
@@ -123,10 +122,9 @@ export function* takeLeading<T>(
op: (action: Action) => Operation<T>,
) {
return yield* spawn(function* (): Operation<void> {
const fd = useActions(pattern);
for (const action of yield* each(fd)) {
while (true) {
const action = yield* take(pattern);
yield* call(() => op(action));
yield* each.next();
}
});
}
17 changes: 2 additions & 15 deletions store/fx.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
Action,
createQueue,
each,
Operation,
Signal,
@@ -13,6 +12,7 @@ import { ActionPattern, matcher } from "../matcher.ts";
import type { ActionWPayload, AnyAction, AnyState } from "../types.ts";
import type { FxStore, StoreUpdater, UpdaterCtx } from "./types.ts";
import { ActionContext, StoreContext } from "./context.ts";
import { createFilterQueue } from "../queue.ts";

export function* updateStore<S extends AnyState>(
updater: StoreUpdater<S> | StoreUpdater<S>[],
@@ -62,20 +62,7 @@ export function* put(action: AnyAction | AnyAction[]) {
});
}

function createFilterQueue<T, TClose>(predicate: (v: T) => boolean) {
const queue = createQueue<T, TClose>();

return {
...queue,
add(value: T) {
if (predicate(value)) {
queue.add(value);
}
},
};
}

export function useActions(pattern: ActionPattern): Stream<AnyAction, void> {
function useActions(pattern: ActionPattern): Stream<AnyAction, void> {
return {
*subscribe() {
const actions = yield* ActionContext;