Server: Phase 2 (REVIEW not respected yet)
This commit is contained in:
1 parent
5d16ded553
commit
142b47674d
4271 files changed
+1203269
No files matched your search
+47
@@ -0,0 +1,47 @@
|
||||
import { createAtom, toObserver } from "./atom.js";
|
||||
|
||||
//#region src/store.ts
|
||||
var Store = class {
|
||||
constructor(valueOrFn, actionsFactory) {
|
||||
this.atom = createAtom(valueOrFn);
|
||||
this.get = this.get.bind(this);
|
||||
this.setState = this.setState.bind(this);
|
||||
this.subscribe = this.subscribe.bind(this);
|
||||
if (actionsFactory) this.actions = actionsFactory(this);
|
||||
}
|
||||
setState(updater) {
|
||||
this.atom.set(updater);
|
||||
}
|
||||
get state() {
|
||||
return this.atom.get();
|
||||
}
|
||||
get() {
|
||||
return this.state;
|
||||
}
|
||||
subscribe(observerOrFn) {
|
||||
return this.atom.subscribe(toObserver(observerOrFn));
|
||||
}
|
||||
};
|
||||
var ReadonlyStore = class {
|
||||
constructor(valueOrFn) {
|
||||
this.atom = createAtom(valueOrFn);
|
||||
}
|
||||
get state() {
|
||||
return this.atom.get();
|
||||
}
|
||||
get() {
|
||||
return this.state;
|
||||
}
|
||||
subscribe(observerOrFn) {
|
||||
return this.atom.subscribe(toObserver(observerOrFn));
|
||||
}
|
||||
};
|
||||
function createStore(valueOrFn, actions) {
|
||||
if (typeof valueOrFn === "function") return new ReadonlyStore(valueOrFn);
|
||||
if (actions) return new Store(valueOrFn, actions);
|
||||
return new Store(valueOrFn);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { ReadonlyStore, Store, createStore };
|
||||
//# sourceMappingURL=store.js.map
|
||||
Reference in new issue
Block a user