Skip to content

Commit

Permalink
feat(readonly): implement readonly operator
Browse files Browse the repository at this point in the history
  • Loading branch information
chshanovskiy committed Jan 14, 2024
1 parent d703b71 commit 2df61ba
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/readonly/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { Store, Event } from 'effector';
import { Store, Event, is, combine } from 'effector';

export function readonly<T extends unknown>(source: Store<T>): Store<T>;
export function readonly<T extends unknown>(source: Event<T>): Event<T>;

export function readonly<T extends unknown>(source: Store<T> | Event<T>) {
return source.map((value) => value, { skipVoid: false });
if (is.store(source)) {
return source.map((value) => value, { skipVoid: false });
}

if (is.event(source)) {
return source.map((value) => value);
}

return source;
}

0 comments on commit 2df61ba

Please sign in to comment.