chem-rx 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Atom.d.ts CHANGED
@@ -1,29 +1,64 @@
1
1
  import { BehaviorSubject, Observable, OperatorFunction, Subscription } from "rxjs";
2
2
  export type AtomTuple<T> = {
3
- [K in keyof T]: Atom<T[K]>;
3
+ [K in keyof T]: ReadOnlyAtom<T[K]>;
4
4
  };
5
- export declare class Atom<T> {
5
+ export declare class ReadOnlyAtom<T> {
6
6
  _behavior$: BehaviorSubject<T>;
7
7
  _parent?: BehaviorSubject<T>[];
8
8
  _bonds: BehaviorSubject<T>[];
9
9
  _fromObservable: Observable<T> | null;
10
10
  _fromObservableSubscription: Subscription | null;
11
- static combine<A extends readonly unknown[]>(...atoms: readonly [...AtomTuple<A>]): Atom<A>;
12
11
  constructor(_value: T | Observable<T>);
13
- push(nextVal: T): void;
14
- transform(): Atom<T>;
15
- transform<A>(op1: OperatorFunction<T, A>): Atom<A>;
16
- transform<A, B>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>): Atom<B>;
17
- transform<A, B, C>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>): Atom<C>;
18
- transform<A, B, C, D>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>): Atom<D>;
19
- transform<A, B, C, D, E>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>): Atom<E>;
20
- transform<A, B, C, D, E, F>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>): Atom<F>;
21
- transform<A, B, C, D, E, F, G>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>): Atom<G>;
22
- transform<A, B, C, D, E, F, G, H>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>, op8: OperatorFunction<G, H>): Atom<H>;
23
- transform<A, B, C, D, E, F, G, H, I>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>, op8: OperatorFunction<G, H>, op9: OperatorFunction<H, I>): Atom<I>;
24
- transform<A, B, C, D, E, F, G, H, I>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>, op8: OperatorFunction<G, H>, op9: OperatorFunction<H, I>, ...operations: OperatorFunction<any, any>[]): Atom<unknown>;
12
+ pipe(): ReadOnlyAtom<T>;
13
+ pipe<A>(op1: OperatorFunction<T, A>): ReadOnlyAtom<A>;
14
+ pipe<A, B>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>): ReadOnlyAtom<B>;
15
+ pipe<A, B, C>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>): ReadOnlyAtom<C>;
16
+ pipe<A, B, C, D>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>): ReadOnlyAtom<D>;
17
+ pipe<A, B, C, D, E>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>): ReadOnlyAtom<E>;
18
+ pipe<A, B, C, D, E, F>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>): ReadOnlyAtom<F>;
19
+ pipe<A, B, C, D, E, F, G>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>): ReadOnlyAtom<G>;
20
+ pipe<A, B, C, D, E, F, G, H>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>, op8: OperatorFunction<G, H>): ReadOnlyAtom<H>;
21
+ pipe<A, B, C, D, E, F, G, H, I>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>, op8: OperatorFunction<G, H>, op9: OperatorFunction<H, I>): ReadOnlyAtom<I>;
22
+ pipe<A, B, C, D, E, F, G, H, I>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>, op8: OperatorFunction<G, H>, op9: OperatorFunction<H, I>, ...operations: OperatorFunction<any, any>[]): ReadOnlyAtom<unknown>;
23
+ derive<A>(deriveFn: (value: T, index: number) => A): ReadOnlyAtom<A>;
25
24
  subscribe(...params: Parameters<BehaviorSubject<T>["subscribe"]>): Subscription;
26
- getValue(): T;
25
+ value(): T;
27
26
  dispose(): void;
27
+ get(key: T extends (infer W)[] ? number : T extends {
28
+ [key in keyof T]: infer W;
29
+ } ? keyof T : undefined): T extends (infer W)[] ? T[number] : T extends {
30
+ [key in keyof T]: infer W;
31
+ } ? T[keyof T] : undefined;
32
+ select<K extends keyof T>(key: K): T[K] extends (infer W)[] ? ArrayAtom<W> : T[K] extends {
33
+ [key: string | symbol]: infer W;
34
+ } ? ObjectAtom<T[K]> : BaseAtom<T[K]>;
35
+ }
36
+ export declare class BaseAtom<T> extends ReadOnlyAtom<T> {
37
+ set(nextVal: T): void;
38
+ }
39
+ export declare class ArrayAtom<T> extends ReadOnlyAtom<T[]> {
40
+ constructor(initialValue: T[]);
41
+ push(nextVal: T): void;
42
+ }
43
+ export declare class ObjectAtom<T extends {
44
+ [key in K]: V;
45
+ }, K extends string | number | symbol = keyof T, V = T[K]> extends ReadOnlyAtom<T> {
46
+ set(nextKey: K, nextValue: V): void;
47
+ }
48
+ export declare function Atom<T>(value: T extends {
49
+ [key: string]: infer V;
50
+ } | any[] ? never : Observable<T>): BaseAtom<T>;
51
+ export declare function Atom<T extends any[]>(value: Observable<T>): ArrayAtom<T[number]>;
52
+ export declare function Atom<T>(value: T extends {
53
+ [key in keyof T]: infer V;
54
+ } ? Observable<T> : never): ObjectAtom<T>;
55
+ export declare function Atom<T extends any[]>(value: T): ArrayAtom<T[number]>;
56
+ export declare function Atom<T extends {
57
+ [key: string]: T[keyof T];
58
+ }>(value: T): ObjectAtom<T>;
59
+ export declare function Atom<T>(value: T): BaseAtom<T>;
60
+ export declare function Atom<T>(value: T, readOnly?: boolean): ReadOnlyAtom<T>;
61
+ export declare namespace Atom {
62
+ var combine: <A extends readonly unknown[]>(...atoms_0: AtomTuple<A>) => ReadOnlyAtom<A>;
28
63
  }
29
64
  //# sourceMappingURL=Atom.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Atom.d.ts","sourceRoot":"","sources":["../src/Atom.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAGf,UAAU,EACV,gBAAgB,EAChB,YAAY,EACb,MAAM,MAAM,CAAC;AA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BAAgB,IAAI,CAAC,CAAC,SAAS;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;CAAE,EAC1D,KAAK,EAAE,CAAC,GACP,UAAU,CAAC,CAAC,CAAC,CAAC;AAGjB,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;AAG/C,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;yBAAvD,IAAI"}
package/dist/Signal.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { Subject, Subscription } from "rxjs";
2
- export declare class Signal<T = void> {
1
+ import { Subject } from "rxjs";
2
+ export declare class BaseSignal<T = any> {
3
3
  _subject$: Subject<T>;
4
4
  constructor();
5
5
  ping(value: T): void;
6
- subscribe(...params: Parameters<Subject<T>["subscribe"]>): Subscription;
7
- dispose(): void;
6
+ subscribe(...params: Parameters<Subject<T>["subscribe"]>): import("rxjs").Subscription;
8
7
  }
8
+ export declare function Signal<T>(): void;
9
9
  //# sourceMappingURL=Signal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Signal.d.ts","sourceRoot":"","sources":["../src/Signal.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAIP,YAAY,EACb,MAAM,MAAM,CAAC;AAGd,qBAAa,MAAM,CAAC,CAAC,GAAG,IAAI;IAC1B,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;;IAOtB,IAAI,CAAC,KAAK,EAAE,CAAC;IAIb,SAAS,CAAC,GAAG,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IAKxD,OAAO;CAGR"}
1
+ {"version":3,"file":"Signal.d.ts","sourceRoot":"","sources":["../src/Signal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,qBAAa,UAAU,CAAC,CAAC,GAAG,GAAG;IAC7B,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;;IAOtB,IAAI,CAAC,KAAK,EAAE,CAAC;IAIb,SAAS,CAAC,GAAG,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;CAGzD;AAED,wBAAgB,MAAM,CAAC,CAAC,UAAM"}
package/dist/index.cjs.js CHANGED
@@ -3,17 +3,66 @@
3
3
  var rxjs = require('rxjs');
4
4
  var react = require('react');
5
5
 
6
- var Atom = /*#__PURE__*/function () {
7
- Atom.combine = function combine() {
8
- for (var _len = arguments.length, atoms = new Array(_len), _key = 0; _key < _len; _key++) {
9
- atoms[_key] = arguments[_key];
6
+ function _extends() {
7
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
8
+ for (var i = 1; i < arguments.length; i++) {
9
+ var source = arguments[i];
10
+ for (var key in source) {
11
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
12
+ target[key] = source[key];
13
+ }
14
+ }
10
15
  }
11
- var observable = rxjs.combineLatest.apply(void 0, atoms.map(function (a) {
12
- return a._behavior$;
13
- }));
14
- return new Atom(observable);
16
+ return target;
17
+ };
18
+ return _extends.apply(this, arguments);
19
+ }
20
+ function _inheritsLoose(subClass, superClass) {
21
+ subClass.prototype = Object.create(superClass.prototype);
22
+ subClass.prototype.constructor = subClass;
23
+ _setPrototypeOf(subClass, superClass);
24
+ }
25
+ function _setPrototypeOf(o, p) {
26
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
27
+ o.__proto__ = p;
28
+ return o;
15
29
  };
16
- function Atom(_value) {
30
+ return _setPrototypeOf(o, p);
31
+ }
32
+ function _unsupportedIterableToArray(o, minLen) {
33
+ if (!o) return;
34
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
35
+ var n = Object.prototype.toString.call(o).slice(8, -1);
36
+ if (n === "Object" && o.constructor) n = o.constructor.name;
37
+ if (n === "Map" || n === "Set") return Array.from(o);
38
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
39
+ }
40
+ function _arrayLikeToArray(arr, len) {
41
+ if (len == null || len > arr.length) len = arr.length;
42
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
43
+ return arr2;
44
+ }
45
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
46
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
47
+ if (it) return (it = it.call(o)).next.bind(it);
48
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
49
+ if (it) o = it;
50
+ var i = 0;
51
+ return function () {
52
+ if (i >= o.length) return {
53
+ done: true
54
+ };
55
+ return {
56
+ done: false,
57
+ value: o[i++]
58
+ };
59
+ };
60
+ }
61
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
62
+ }
63
+
64
+ var ReadOnlyAtom = /*#__PURE__*/function () {
65
+ function ReadOnlyAtom(_value) {
17
66
  var _this = this;
18
67
  this._bonds = [];
19
68
  this._fromObservable = null;
@@ -22,31 +71,31 @@ var Atom = /*#__PURE__*/function () {
22
71
  this._fromObservable = _value;
23
72
  this._behavior$ = new rxjs.BehaviorSubject(null);
24
73
  this._fromObservableSubscription = _value.subscribe(function (value) {
25
- _this.push(value);
74
+ _this._behavior$.next(value);
26
75
  });
27
76
  } else {
28
77
  // if it's just a value just use a regular behavior subject
29
78
  this._behavior$ = new rxjs.BehaviorSubject(_value);
30
79
  }
31
80
  }
32
- var _proto = Atom.prototype;
33
- _proto.push = function push(nextVal) {
34
- this._behavior$.next(nextVal);
35
- }
36
81
 
37
82
  // taken from Observable
38
- ;
39
- _proto.transform = function transform() {
83
+ var _proto = ReadOnlyAtom.prototype;
84
+ _proto.pipe = function pipe() {
40
85
  var _this$_behavior$;
41
86
  // @ts-ignore can't match overloaded function
42
87
  var observable = (_this$_behavior$ = this._behavior$).pipe.apply(_this$_behavior$, arguments);
43
- return new Atom(observable);
88
+ var newAtom = new ReadOnlyAtom(observable);
89
+ return newAtom;
90
+ };
91
+ _proto.derive = function derive(deriveFn) {
92
+ return this.pipe(rxjs.map(deriveFn));
44
93
  };
45
94
  _proto.subscribe = function subscribe() {
46
95
  var _this$_behavior$2;
47
96
  return (_this$_behavior$2 = this._behavior$).subscribe.apply(_this$_behavior$2, arguments);
48
97
  };
49
- _proto.getValue = function getValue() {
98
+ _proto.value = function value() {
50
99
  return this._behavior$.getValue();
51
100
  }
52
101
 
@@ -56,11 +105,128 @@ var Atom = /*#__PURE__*/function () {
56
105
  var _this$_fromObservable;
57
106
  (_this$_fromObservable = this._fromObservableSubscription) == null ? void 0 : _this$_fromObservable.unsubscribe();
58
107
  };
59
- return Atom;
108
+ _proto.get = function get(key) {
109
+ var val = this.value();
110
+ // @ts-ignore Can't figure out this type so i'm REALLY cheating
111
+ return val[key];
112
+ };
113
+ _proto.select = function select(key) {
114
+ var newObs = this._behavior$.pipe(rxjs.distinctUntilKeyChanged(key), rxjs.map(function (k) {
115
+ return k == null ? void 0 : k[key];
116
+ }));
117
+ // Can't get typescript to recognize the types here so I'm cheating
118
+ return Atom(newObs);
119
+ };
120
+ return ReadOnlyAtom;
60
121
  }();
122
+ var BaseAtom = /*#__PURE__*/function (_ReadOnlyAtom) {
123
+ _inheritsLoose(BaseAtom, _ReadOnlyAtom);
124
+ function BaseAtom() {
125
+ return _ReadOnlyAtom.apply(this, arguments) || this;
126
+ }
127
+ var _proto2 = BaseAtom.prototype;
128
+ _proto2.set = function set(nextVal) {
129
+ this._behavior$.next(nextVal);
130
+ };
131
+ return BaseAtom;
132
+ }(ReadOnlyAtom);
133
+ var ArrayAtom = /*#__PURE__*/function (_ReadOnlyAtom2) {
134
+ _inheritsLoose(ArrayAtom, _ReadOnlyAtom2);
135
+ function ArrayAtom(initialValue) {
136
+ return _ReadOnlyAtom2.call(this, initialValue) || this;
137
+ }
138
+ var _proto3 = ArrayAtom.prototype;
139
+ _proto3.push = function push(nextVal) {
140
+ this._behavior$.next([].concat(this._behavior$.getValue(), [nextVal]));
141
+ };
142
+ return ArrayAtom;
143
+ }(ReadOnlyAtom);
144
+ //
145
+ // export class ReadOnlyObjectAtom<
146
+ // T extends {
147
+ // [key in K]: V;
148
+ // },
149
+ // K extends string | number | symbol = keyof T,
150
+ // V = T[K]
151
+ // > extends ReadOnlyAtom<T> {
152
+ // get(nextKey: K) {
153
+ // return this.value()[nextKey];
154
+ // }
155
+ //
156
+ // select<K extends keyof T>(
157
+ // key: K
158
+ // ): T[K] extends (infer W)[]
159
+ // ? ArrayAtom<W>
160
+ // : T[K] extends { [key in infer L]?: infer W }
161
+ // ? ObjectAtom<T[K]>
162
+ // : BaseAtom<T> {
163
+ // const newObs = this._behavior$.pipe(
164
+ // distinctUntilKeyChanged(key),
165
+ // map((k) => k?.[key])
166
+ // );
167
+ // // Can't get typescript to recognize the types here so I'm cheating
168
+ // return Atom(newObs) as unknown as T[K] extends (infer W)[]
169
+ // ? ArrayAtom<W>
170
+ // : T[K] extends { [key in infer L]?: infer W }
171
+ // ? ObjectAtom<T[K]>
172
+ // : BaseAtom<T>;
173
+ // }
174
+ // }
175
+
176
+ var ObjectAtom = /*#__PURE__*/function (_ReadOnlyAtom3) {
177
+ _inheritsLoose(ObjectAtom, _ReadOnlyAtom3);
178
+ function ObjectAtom() {
179
+ return _ReadOnlyAtom3.apply(this, arguments) || this;
180
+ }
181
+ var _proto4 = ObjectAtom.prototype;
182
+ _proto4.set = function set(nextKey, nextValue) {
183
+ var _extends2;
184
+ this._behavior$.next(_extends({}, this._behavior$.getValue(), (_extends2 = {}, _extends2[nextKey] = nextValue, _extends2)));
185
+ };
186
+ return ObjectAtom;
187
+ }(ReadOnlyAtom);
188
+
189
+ // catch-all for developers
190
+ // export type AnyAtom<T> = BaseAtom<T> | ArrayAtom<T> | ObjectAtom<T>;
191
+
192
+ // observable type (primitive)
193
+ // observable<array> type
194
+ // observable<object> type
195
+ // array type
196
+ // object type
197
+ // primitive type
198
+ // readonly type
199
+ // function definition
200
+ function Atom(_value, readOnly) {
201
+ if (readOnly === void 0) {
202
+ readOnly = false;
203
+ }
204
+ var atom;
205
+ if (readOnly) {
206
+ atom = new ReadOnlyAtom(_value);
207
+ } else if (Array.isArray(_value)) {
208
+ atom = new ArrayAtom(_value); // For arrays
209
+ } else if (typeof _value === "object" && _value !== null) {
210
+ atom = new ObjectAtom(_value); // For objects
211
+ } else {
212
+ atom = new BaseAtom(_value); // For other types
213
+ }
214
+
215
+ return atom;
216
+ }
217
+ Atom.combine = function () {
218
+ for (var _len = arguments.length, atoms = new Array(_len), _key = 0; _key < _len; _key++) {
219
+ atoms[_key] = arguments[_key];
220
+ }
221
+ var observable = rxjs.combineLatest.apply(void 0, atoms.map(function (a) {
222
+ return a._behavior$;
223
+ }));
224
+ var newAtom = new ReadOnlyAtom(observable);
225
+ return newAtom;
226
+ };
61
227
 
62
228
  function useAtom(atom) {
63
- var _useState = react.useState(atom.getValue()),
229
+ var _useState = react.useState(atom.value()),
64
230
  value = _useState[0],
65
231
  setValue = _useState[1];
66
232
  react.useEffect(function () {
@@ -74,36 +240,19 @@ function useAtom(atom) {
74
240
  return value;
75
241
  }
76
242
 
77
- function _unsupportedIterableToArray(o, minLen) {
78
- if (!o) return;
79
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
80
- var n = Object.prototype.toString.call(o).slice(8, -1);
81
- if (n === "Object" && o.constructor) n = o.constructor.name;
82
- if (n === "Map" || n === "Set") return Array.from(o);
83
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
84
- }
85
- function _arrayLikeToArray(arr, len) {
86
- if (len == null || len > arr.length) len = arr.length;
87
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
88
- return arr2;
89
- }
90
- function _createForOfIteratorHelperLoose(o, allowArrayLike) {
91
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
92
- if (it) return (it = it.call(o)).next.bind(it);
93
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
94
- if (it) o = it;
95
- var i = 0;
243
+ function useSelectAtom(atom, key) {
244
+ var _useState = react.useState(atom.get(key)),
245
+ value = _useState[0],
246
+ setValue = _useState[1];
247
+ react.useEffect(function () {
248
+ var subscription = atom.select(key).subscribe(function (val) {
249
+ setValue(val);
250
+ });
96
251
  return function () {
97
- if (i >= o.length) return {
98
- done: true
99
- };
100
- return {
101
- done: false,
102
- value: o[i++]
103
- };
252
+ subscription.unsubscribe();
104
253
  };
105
- }
106
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
254
+ }, [atom]);
255
+ return value;
107
256
  }
108
257
 
109
258
  function hydrateAtoms(values) {
@@ -115,29 +264,10 @@ function hydrateAtoms(values) {
115
264
  }
116
265
  }
117
266
 
118
- var Signal = /*#__PURE__*/function () {
119
- function Signal() {
120
- // if it's just a value just use a regular behavior subject
121
- this._subject$ = new rxjs.Subject();
122
- }
123
- var _proto = Signal.prototype;
124
- _proto.ping = function ping(value) {
125
- this._subject$.next(value);
126
- };
127
- _proto.subscribe = function subscribe() {
128
- var _this$_subject$;
129
- return (_this$_subject$ = this._subject$).subscribe.apply(_this$_subject$, arguments);
130
- }
131
-
132
- // not needed?
133
- ;
134
- _proto.dispose = function dispose() {
135
- this._subject$.unsubscribe();
136
- };
137
- return Signal;
138
- }();
267
+ function Signal() {}
139
268
 
140
269
  exports.Atom = Atom;
141
270
  exports.Signal = Signal;
142
271
  exports.hydrateAtoms = hydrateAtoms;
143
272
  exports.useAtom = useAtom;
273
+ exports.useSelectAtom = useSelectAtom;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { Atom } from "./Atom";
2
2
  export { useAtom } from "./useAtom";
3
+ export { useSelectAtom } from "./useSelectAtom";
3
4
  export { hydrateAtoms } from "./hydrateAtoms";
4
5
  export { Signal } from "./Signal";
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
@@ -1,17 +1,66 @@
1
1
  var chemicalRx = (function (exports, rxjs, react) {
2
2
  'use strict';
3
3
 
4
- var Atom = /*#__PURE__*/function () {
5
- Atom.combine = function combine() {
6
- for (var _len = arguments.length, atoms = new Array(_len), _key = 0; _key < _len; _key++) {
7
- atoms[_key] = arguments[_key];
4
+ function _extends() {
5
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
6
+ for (var i = 1; i < arguments.length; i++) {
7
+ var source = arguments[i];
8
+ for (var key in source) {
9
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
10
+ target[key] = source[key];
11
+ }
12
+ }
8
13
  }
9
- var observable = rxjs.combineLatest.apply(void 0, atoms.map(function (a) {
10
- return a._behavior$;
11
- }));
12
- return new Atom(observable);
14
+ return target;
15
+ };
16
+ return _extends.apply(this, arguments);
17
+ }
18
+ function _inheritsLoose(subClass, superClass) {
19
+ subClass.prototype = Object.create(superClass.prototype);
20
+ subClass.prototype.constructor = subClass;
21
+ _setPrototypeOf(subClass, superClass);
22
+ }
23
+ function _setPrototypeOf(o, p) {
24
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
25
+ o.__proto__ = p;
26
+ return o;
13
27
  };
14
- function Atom(_value) {
28
+ return _setPrototypeOf(o, p);
29
+ }
30
+ function _unsupportedIterableToArray(o, minLen) {
31
+ if (!o) return;
32
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
33
+ var n = Object.prototype.toString.call(o).slice(8, -1);
34
+ if (n === "Object" && o.constructor) n = o.constructor.name;
35
+ if (n === "Map" || n === "Set") return Array.from(o);
36
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
37
+ }
38
+ function _arrayLikeToArray(arr, len) {
39
+ if (len == null || len > arr.length) len = arr.length;
40
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
41
+ return arr2;
42
+ }
43
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
44
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
45
+ if (it) return (it = it.call(o)).next.bind(it);
46
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
47
+ if (it) o = it;
48
+ var i = 0;
49
+ return function () {
50
+ if (i >= o.length) return {
51
+ done: true
52
+ };
53
+ return {
54
+ done: false,
55
+ value: o[i++]
56
+ };
57
+ };
58
+ }
59
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
60
+ }
61
+
62
+ var ReadOnlyAtom = /*#__PURE__*/function () {
63
+ function ReadOnlyAtom(_value) {
15
64
  var _this = this;
16
65
  this._bonds = [];
17
66
  this._fromObservable = null;
@@ -20,31 +69,31 @@ var chemicalRx = (function (exports, rxjs, react) {
20
69
  this._fromObservable = _value;
21
70
  this._behavior$ = new rxjs.BehaviorSubject(null);
22
71
  this._fromObservableSubscription = _value.subscribe(function (value) {
23
- _this.push(value);
72
+ _this._behavior$.next(value);
24
73
  });
25
74
  } else {
26
75
  // if it's just a value just use a regular behavior subject
27
76
  this._behavior$ = new rxjs.BehaviorSubject(_value);
28
77
  }
29
78
  }
30
- var _proto = Atom.prototype;
31
- _proto.push = function push(nextVal) {
32
- this._behavior$.next(nextVal);
33
- }
34
79
 
35
80
  // taken from Observable
36
- ;
37
- _proto.transform = function transform() {
81
+ var _proto = ReadOnlyAtom.prototype;
82
+ _proto.pipe = function pipe() {
38
83
  var _this$_behavior$;
39
84
  // @ts-ignore can't match overloaded function
40
85
  var observable = (_this$_behavior$ = this._behavior$).pipe.apply(_this$_behavior$, arguments);
41
- return new Atom(observable);
86
+ var newAtom = new ReadOnlyAtom(observable);
87
+ return newAtom;
88
+ };
89
+ _proto.derive = function derive(deriveFn) {
90
+ return this.pipe(rxjs.map(deriveFn));
42
91
  };
43
92
  _proto.subscribe = function subscribe() {
44
93
  var _this$_behavior$2;
45
94
  return (_this$_behavior$2 = this._behavior$).subscribe.apply(_this$_behavior$2, arguments);
46
95
  };
47
- _proto.getValue = function getValue() {
96
+ _proto.value = function value() {
48
97
  return this._behavior$.getValue();
49
98
  }
50
99
 
@@ -54,11 +103,128 @@ var chemicalRx = (function (exports, rxjs, react) {
54
103
  var _this$_fromObservable;
55
104
  (_this$_fromObservable = this._fromObservableSubscription) == null ? void 0 : _this$_fromObservable.unsubscribe();
56
105
  };
57
- return Atom;
106
+ _proto.get = function get(key) {
107
+ var val = this.value();
108
+ // @ts-ignore Can't figure out this type so i'm REALLY cheating
109
+ return val[key];
110
+ };
111
+ _proto.select = function select(key) {
112
+ var newObs = this._behavior$.pipe(rxjs.distinctUntilKeyChanged(key), rxjs.map(function (k) {
113
+ return k == null ? void 0 : k[key];
114
+ }));
115
+ // Can't get typescript to recognize the types here so I'm cheating
116
+ return Atom(newObs);
117
+ };
118
+ return ReadOnlyAtom;
58
119
  }();
120
+ var BaseAtom = /*#__PURE__*/function (_ReadOnlyAtom) {
121
+ _inheritsLoose(BaseAtom, _ReadOnlyAtom);
122
+ function BaseAtom() {
123
+ return _ReadOnlyAtom.apply(this, arguments) || this;
124
+ }
125
+ var _proto2 = BaseAtom.prototype;
126
+ _proto2.set = function set(nextVal) {
127
+ this._behavior$.next(nextVal);
128
+ };
129
+ return BaseAtom;
130
+ }(ReadOnlyAtom);
131
+ var ArrayAtom = /*#__PURE__*/function (_ReadOnlyAtom2) {
132
+ _inheritsLoose(ArrayAtom, _ReadOnlyAtom2);
133
+ function ArrayAtom(initialValue) {
134
+ return _ReadOnlyAtom2.call(this, initialValue) || this;
135
+ }
136
+ var _proto3 = ArrayAtom.prototype;
137
+ _proto3.push = function push(nextVal) {
138
+ this._behavior$.next([].concat(this._behavior$.getValue(), [nextVal]));
139
+ };
140
+ return ArrayAtom;
141
+ }(ReadOnlyAtom);
142
+ //
143
+ // export class ReadOnlyObjectAtom<
144
+ // T extends {
145
+ // [key in K]: V;
146
+ // },
147
+ // K extends string | number | symbol = keyof T,
148
+ // V = T[K]
149
+ // > extends ReadOnlyAtom<T> {
150
+ // get(nextKey: K) {
151
+ // return this.value()[nextKey];
152
+ // }
153
+ //
154
+ // select<K extends keyof T>(
155
+ // key: K
156
+ // ): T[K] extends (infer W)[]
157
+ // ? ArrayAtom<W>
158
+ // : T[K] extends { [key in infer L]?: infer W }
159
+ // ? ObjectAtom<T[K]>
160
+ // : BaseAtom<T> {
161
+ // const newObs = this._behavior$.pipe(
162
+ // distinctUntilKeyChanged(key),
163
+ // map((k) => k?.[key])
164
+ // );
165
+ // // Can't get typescript to recognize the types here so I'm cheating
166
+ // return Atom(newObs) as unknown as T[K] extends (infer W)[]
167
+ // ? ArrayAtom<W>
168
+ // : T[K] extends { [key in infer L]?: infer W }
169
+ // ? ObjectAtom<T[K]>
170
+ // : BaseAtom<T>;
171
+ // }
172
+ // }
173
+
174
+ var ObjectAtom = /*#__PURE__*/function (_ReadOnlyAtom3) {
175
+ _inheritsLoose(ObjectAtom, _ReadOnlyAtom3);
176
+ function ObjectAtom() {
177
+ return _ReadOnlyAtom3.apply(this, arguments) || this;
178
+ }
179
+ var _proto4 = ObjectAtom.prototype;
180
+ _proto4.set = function set(nextKey, nextValue) {
181
+ var _extends2;
182
+ this._behavior$.next(_extends({}, this._behavior$.getValue(), (_extends2 = {}, _extends2[nextKey] = nextValue, _extends2)));
183
+ };
184
+ return ObjectAtom;
185
+ }(ReadOnlyAtom);
186
+
187
+ // catch-all for developers
188
+ // export type AnyAtom<T> = BaseAtom<T> | ArrayAtom<T> | ObjectAtom<T>;
189
+
190
+ // observable type (primitive)
191
+ // observable<array> type
192
+ // observable<object> type
193
+ // array type
194
+ // object type
195
+ // primitive type
196
+ // readonly type
197
+ // function definition
198
+ function Atom(_value, readOnly) {
199
+ if (readOnly === void 0) {
200
+ readOnly = false;
201
+ }
202
+ var atom;
203
+ if (readOnly) {
204
+ atom = new ReadOnlyAtom(_value);
205
+ } else if (Array.isArray(_value)) {
206
+ atom = new ArrayAtom(_value); // For arrays
207
+ } else if (typeof _value === "object" && _value !== null) {
208
+ atom = new ObjectAtom(_value); // For objects
209
+ } else {
210
+ atom = new BaseAtom(_value); // For other types
211
+ }
212
+
213
+ return atom;
214
+ }
215
+ Atom.combine = function () {
216
+ for (var _len = arguments.length, atoms = new Array(_len), _key = 0; _key < _len; _key++) {
217
+ atoms[_key] = arguments[_key];
218
+ }
219
+ var observable = rxjs.combineLatest.apply(void 0, atoms.map(function (a) {
220
+ return a._behavior$;
221
+ }));
222
+ var newAtom = new ReadOnlyAtom(observable);
223
+ return newAtom;
224
+ };
59
225
 
60
226
  function useAtom(atom) {
61
- var _useState = react.useState(atom.getValue()),
227
+ var _useState = react.useState(atom.value()),
62
228
  value = _useState[0],
63
229
  setValue = _useState[1];
64
230
  react.useEffect(function () {
@@ -72,36 +238,19 @@ var chemicalRx = (function (exports, rxjs, react) {
72
238
  return value;
73
239
  }
74
240
 
75
- function _unsupportedIterableToArray(o, minLen) {
76
- if (!o) return;
77
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
78
- var n = Object.prototype.toString.call(o).slice(8, -1);
79
- if (n === "Object" && o.constructor) n = o.constructor.name;
80
- if (n === "Map" || n === "Set") return Array.from(o);
81
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
82
- }
83
- function _arrayLikeToArray(arr, len) {
84
- if (len == null || len > arr.length) len = arr.length;
85
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
86
- return arr2;
87
- }
88
- function _createForOfIteratorHelperLoose(o, allowArrayLike) {
89
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
90
- if (it) return (it = it.call(o)).next.bind(it);
91
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
92
- if (it) o = it;
93
- var i = 0;
241
+ function useSelectAtom(atom, key) {
242
+ var _useState = react.useState(atom.get(key)),
243
+ value = _useState[0],
244
+ setValue = _useState[1];
245
+ react.useEffect(function () {
246
+ var subscription = atom.select(key).subscribe(function (val) {
247
+ setValue(val);
248
+ });
94
249
  return function () {
95
- if (i >= o.length) return {
96
- done: true
97
- };
98
- return {
99
- done: false,
100
- value: o[i++]
101
- };
250
+ subscription.unsubscribe();
102
251
  };
103
- }
104
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
252
+ }, [atom]);
253
+ return value;
105
254
  }
106
255
 
107
256
  function hydrateAtoms(values) {
@@ -113,32 +262,13 @@ var chemicalRx = (function (exports, rxjs, react) {
113
262
  }
114
263
  }
115
264
 
116
- var Signal = /*#__PURE__*/function () {
117
- function Signal() {
118
- // if it's just a value just use a regular behavior subject
119
- this._subject$ = new rxjs.Subject();
120
- }
121
- var _proto = Signal.prototype;
122
- _proto.ping = function ping(value) {
123
- this._subject$.next(value);
124
- };
125
- _proto.subscribe = function subscribe() {
126
- var _this$_subject$;
127
- return (_this$_subject$ = this._subject$).subscribe.apply(_this$_subject$, arguments);
128
- }
129
-
130
- // not needed?
131
- ;
132
- _proto.dispose = function dispose() {
133
- this._subject$.unsubscribe();
134
- };
135
- return Signal;
136
- }();
265
+ function Signal() {}
137
266
 
138
267
  exports.Atom = Atom;
139
268
  exports.Signal = Signal;
140
269
  exports.hydrateAtoms = hydrateAtoms;
141
270
  exports.useAtom = useAtom;
271
+ exports.useSelectAtom = useSelectAtom;
142
272
 
143
273
  return exports;
144
274
 
package/dist/index.js CHANGED
@@ -1,11 +1,22 @@
1
- import { combineLatest, isObservable, BehaviorSubject, Subject } from 'rxjs';
1
+ import { combineLatest, isObservable, BehaviorSubject, map, distinctUntilKeyChanged } from 'rxjs';
2
2
  import { useState, useEffect } from 'react';
3
3
 
4
- class Atom {
5
- static combine(...atoms) {
6
- const observable = combineLatest(...atoms.map(a => a._behavior$));
7
- return new Atom(observable);
8
- }
4
+ function _extends() {
5
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
6
+ for (var i = 1; i < arguments.length; i++) {
7
+ var source = arguments[i];
8
+ for (var key in source) {
9
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
10
+ target[key] = source[key];
11
+ }
12
+ }
13
+ }
14
+ return target;
15
+ };
16
+ return _extends.apply(this, arguments);
17
+ }
18
+
19
+ class ReadOnlyAtom {
9
20
  constructor(_value) {
10
21
  this._bonds = [];
11
22
  this._fromObservable = null;
@@ -14,28 +25,29 @@ class Atom {
14
25
  this._fromObservable = _value;
15
26
  this._behavior$ = new BehaviorSubject(null);
16
27
  this._fromObservableSubscription = _value.subscribe(value => {
17
- this.push(value);
28
+ this._behavior$.next(value);
18
29
  });
19
30
  } else {
20
31
  // if it's just a value just use a regular behavior subject
21
32
  this._behavior$ = new BehaviorSubject(_value);
22
33
  }
23
34
  }
24
- push(nextVal) {
25
- this._behavior$.next(nextVal);
26
- }
27
35
 
28
36
  // taken from Observable
29
37
 
30
- transform(...operations) {
38
+ pipe(...operations) {
31
39
  // @ts-ignore can't match overloaded function
32
40
  const observable = this._behavior$.pipe(...operations);
33
- return new Atom(observable);
41
+ const newAtom = new ReadOnlyAtom(observable);
42
+ return newAtom;
43
+ }
44
+ derive(deriveFn) {
45
+ return this.pipe(map(deriveFn));
34
46
  }
35
47
  subscribe(...params) {
36
48
  return this._behavior$.subscribe(...params);
37
49
  }
38
- getValue() {
50
+ value() {
39
51
  return this._behavior$.getValue();
40
52
  }
41
53
 
@@ -44,10 +56,103 @@ class Atom {
44
56
  var _this$_fromObservable;
45
57
  (_this$_fromObservable = this._fromObservableSubscription) == null ? void 0 : _this$_fromObservable.unsubscribe();
46
58
  }
59
+ get(key) {
60
+ const val = this.value();
61
+ // @ts-ignore Can't figure out this type so i'm REALLY cheating
62
+ return val[key];
63
+ }
64
+ select(key) {
65
+ const newObs = this._behavior$.pipe(distinctUntilKeyChanged(key), map(k => k == null ? void 0 : k[key]));
66
+ // Can't get typescript to recognize the types here so I'm cheating
67
+ return Atom(newObs);
68
+ }
69
+ }
70
+ class BaseAtom extends ReadOnlyAtom {
71
+ set(nextVal) {
72
+ this._behavior$.next(nextVal);
73
+ }
74
+ }
75
+ class ArrayAtom extends ReadOnlyAtom {
76
+ constructor(initialValue) {
77
+ super(initialValue);
78
+ }
79
+ push(nextVal) {
80
+ this._behavior$.next([...this._behavior$.getValue(), nextVal]);
81
+ }
82
+ }
83
+ //
84
+ // export class ReadOnlyObjectAtom<
85
+ // T extends {
86
+ // [key in K]: V;
87
+ // },
88
+ // K extends string | number | symbol = keyof T,
89
+ // V = T[K]
90
+ // > extends ReadOnlyAtom<T> {
91
+ // get(nextKey: K) {
92
+ // return this.value()[nextKey];
93
+ // }
94
+ //
95
+ // select<K extends keyof T>(
96
+ // key: K
97
+ // ): T[K] extends (infer W)[]
98
+ // ? ArrayAtom<W>
99
+ // : T[K] extends { [key in infer L]?: infer W }
100
+ // ? ObjectAtom<T[K]>
101
+ // : BaseAtom<T> {
102
+ // const newObs = this._behavior$.pipe(
103
+ // distinctUntilKeyChanged(key),
104
+ // map((k) => k?.[key])
105
+ // );
106
+ // // Can't get typescript to recognize the types here so I'm cheating
107
+ // return Atom(newObs) as unknown as T[K] extends (infer W)[]
108
+ // ? ArrayAtom<W>
109
+ // : T[K] extends { [key in infer L]?: infer W }
110
+ // ? ObjectAtom<T[K]>
111
+ // : BaseAtom<T>;
112
+ // }
113
+ // }
114
+
115
+ class ObjectAtom extends ReadOnlyAtom {
116
+ set(nextKey, nextValue) {
117
+ this._behavior$.next(_extends({}, this._behavior$.getValue(), {
118
+ [nextKey]: nextValue
119
+ }));
120
+ }
121
+ }
122
+
123
+ // catch-all for developers
124
+ // export type AnyAtom<T> = BaseAtom<T> | ArrayAtom<T> | ObjectAtom<T>;
125
+
126
+ // observable type (primitive)
127
+ // observable<array> type
128
+ // observable<object> type
129
+ // array type
130
+ // object type
131
+ // primitive type
132
+ // readonly type
133
+ // function definition
134
+ function Atom(_value, readOnly = false) {
135
+ let atom;
136
+ if (readOnly) {
137
+ atom = new ReadOnlyAtom(_value);
138
+ } else if (Array.isArray(_value)) {
139
+ atom = new ArrayAtom(_value); // For arrays
140
+ } else if (typeof _value === "object" && _value !== null) {
141
+ atom = new ObjectAtom(_value); // For objects
142
+ } else {
143
+ atom = new BaseAtom(_value); // For other types
144
+ }
145
+
146
+ return atom;
47
147
  }
148
+ Atom.combine = (...atoms) => {
149
+ const observable = combineLatest(...atoms.map(a => a._behavior$));
150
+ const newAtom = new ReadOnlyAtom(observable);
151
+ return newAtom;
152
+ };
48
153
 
49
154
  function useAtom(atom) {
50
- const [value, setValue] = useState(atom.getValue());
155
+ const [value, setValue] = useState(atom.value());
51
156
  useEffect(() => {
52
157
  const subscription = atom.subscribe(val => {
53
158
  setValue(val);
@@ -59,28 +164,25 @@ function useAtom(atom) {
59
164
  return value;
60
165
  }
61
166
 
167
+ function useSelectAtom(atom, key) {
168
+ const [value, setValue] = useState(atom.get(key));
169
+ useEffect(() => {
170
+ const subscription = atom.select(key).subscribe(val => {
171
+ setValue(val);
172
+ });
173
+ return () => {
174
+ subscription.unsubscribe();
175
+ };
176
+ }, [atom]);
177
+ return value;
178
+ }
179
+
62
180
  function hydrateAtoms(values) {
63
181
  for (const [atom, value] of values) {
64
182
  atom.push(value);
65
183
  }
66
184
  }
67
185
 
68
- class Signal {
69
- constructor() {
70
- // if it's just a value just use a regular behavior subject
71
- this._subject$ = new Subject();
72
- }
73
- ping(value) {
74
- this._subject$.next(value);
75
- }
76
- subscribe(...params) {
77
- return this._subject$.subscribe(...params);
78
- }
79
-
80
- // not needed?
81
- dispose() {
82
- this._subject$.unsubscribe();
83
- }
84
- }
186
+ function Signal() {}
85
187
 
86
- export { Atom, Signal, hydrateAtoms, useAtom };
188
+ export { Atom, Signal, hydrateAtoms, useAtom, useSelectAtom };
package/dist/useAtom.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { Atom } from "./Atom";
2
- export declare function useAtom<T>(atom: Atom<T>): T;
1
+ import { ReadOnlyAtom } from "./Atom";
2
+ export declare function useAtom<T>(atom: ReadOnlyAtom<T>): T;
3
3
  //# sourceMappingURL=useAtom.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAtom.d.ts","sourceRoot":"","sources":["../src/useAtom.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,wBAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAc3C"}
1
+ {"version":3,"file":"useAtom.d.ts","sourceRoot":"","sources":["../src/useAtom.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,wBAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAcnD"}
@@ -0,0 +1,5 @@
1
+ import { ObjectAtom } from "./Atom";
2
+ export declare function useSelectAtom<T extends {
3
+ [key in K]: V;
4
+ }, K extends string | number | symbol = keyof T, V = T[K]>(atom: ObjectAtom<T>, key: K): T[K];
5
+ //# sourceMappingURL=useSelectAtom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSelectAtom.d.ts","sourceRoot":"","sources":["../src/useSelectAtom.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,wBAAgB,aAAa,CAC3B,CAAC,SAAS;KACP,GAAG,IAAI,CAAC,GAAG,CAAC;CACd,EACD,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,EAC5C,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EACR,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAcnC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chem-rx",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "react state primitives powered by rx.js",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -46,6 +46,7 @@
46
46
  "prebuild": "rimraf dist",
47
47
  "test": "jest",
48
48
  "clean": "rm -rf ./dist",
49
- "build": "npm run prebuild && rollup -c"
49
+ "build": "pnpm run prebuild && rollup -c",
50
+ "bump": "pnpm run build && pnpm version patch"
50
51
  }
51
52
  }
package/src/Atom.ts CHANGED
@@ -14,8 +14,6 @@ export type AtomTuple<T> = {
14
14
  [K in keyof T]: ReadOnlyAtom<T[K]>;
15
15
  };
16
16
 
17
- // export class ReadOnlyAtom<T> {}
18
-
19
17
  export class ReadOnlyAtom<T> {
20
18
  _behavior$: BehaviorSubject<T>;
21
19
 
@@ -1,3 +0,0 @@
1
- import { Atom } from "./Atom";
2
- export declare function hydrateAtoms(values: readonly [Atom<any>, any][]): void;
3
- //# sourceMappingURL=hydrateAtoms.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hydrateAtoms.d.ts","sourceRoot":"","sources":["../src/hydrateAtoms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,QAI/D"}