Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansolid committed Feb 21, 2025
1 parent 9431b88 commit 1f83ebc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
29 changes: 16 additions & 13 deletions packages/solid/src/reactive/observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,22 @@ export function observable<T>(input: Accessor<T>): Observable<T> {
}

type Producer<T> =
| ((setter: Setter<T>) => () => void)
| { subscribe: (fn: (v: T) => void) => (() => void) | { unsubscribe: () => void } };
| ((setter: Setter<T>) => () => void)
| { subscribe: (fn: (v: T) => void) => (() => void) | { unsubscribe: () => void } };

export function from<T>(producer: Producer<T>, initalValue: T): Accessor<T>;
export function from<T>(producer: Producer<T|undefined>): Accessor<T|undefined>;
export function from<T>(producer: Producer<T|undefined>, initalValue: T|undefined = undefined): Accessor<T | undefined> {
const [s, set] = createSignal<T | undefined>(initalValue, { equals: false });
if ("subscribe" in producer) {
const unsub = producer.subscribe(v => set(() => v));
onCleanup(() => ("unsubscribe" in unsub ? unsub.unsubscribe() : unsub()));
} else {
const clean = producer(set);
onCleanup(clean);
}
return s;
export function from<T>(producer: Producer<T | undefined>): Accessor<T | undefined>;
export function from<T>(
producer: Producer<T | undefined>,
initalValue: T | undefined = undefined
): Accessor<T | undefined> {
const [s, set] = createSignal<T | undefined>(initalValue, { equals: false });
if ("subscribe" in producer) {
const unsub = producer.subscribe(v => set(() => v));
onCleanup(() => ("unsubscribe" in unsub ? unsub.unsubscribe() : unsub()));
} else {
const clean = producer(set);
onCleanup(clean);
}
return s;
}
4 changes: 2 additions & 2 deletions packages/solid/src/reactive/signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const DevHooks: {
afterUpdate: null,
afterCreateOwner: null,
afterCreateSignal: null,
afterRegisterGraph: null,
afterRegisterGraph: null
};

export type ComputationState = 0 | 1 | 2;
Expand Down Expand Up @@ -1147,7 +1147,7 @@ export function registerGraph(value: SourceMapValue): void {
else Owner.sourceMap = [value];
value.graph = Owner;
}
if (DevHooks.afterRegisterGraph) DevHooks.afterRegisterGraph(value)
if (DevHooks.afterRegisterGraph) DevHooks.afterRegisterGraph(value);
}

export type ContextProviderComponent<T> = FlowComponent<{ value: T }>;
Expand Down
2 changes: 1 addition & 1 deletion packages/solid/test/dev.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ describe("Dev features", () => {
expect(cb).toHaveBeenLastCalledWith(owner.sourceMap![1]);
expect(owner.sourceMap).toHaveLength(2);

const customValue = {value: 3};
const customValue = { value: 3 };
DEV!.registerGraph(customValue);
expect(cb).toHaveBeenCalledTimes(3);
expect(cb).toHaveBeenLastCalledWith(customValue);
Expand Down

0 comments on commit 1f83ebc

Please sign in to comment.