chem-rx 0.0.8 → 0.0.10

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
@@ -27,34 +27,44 @@ export declare class ReadOnlyAtom<T> {
27
27
  get<K extends keyof T>(key: K): T extends (infer W)[] ? T[number] : T extends {
28
28
  [key in keyof T]: infer W;
29
29
  } ? T[keyof T] : undefined;
30
- select<K extends keyof T>(key: K): T[K] extends (infer W)[] ? ArrayAtom<W> : T[K] extends {
31
- [key: string | symbol]: infer W;
32
- } ? ObjectAtom<T[K]> : BaseAtom<T[K]>;
30
+ select<K extends keyof T>(key: K): T[K] extends (infer W)[] ? ArrayAtom<W> : BaseAtom<T[K]>;
33
31
  }
34
32
  export declare class BaseAtom<T> extends ReadOnlyAtom<T> {
35
- set(nextVal: T): void;
33
+ next(nextVal: T): void;
34
+ set(nextKey: keyof T, nextValue: T[keyof T]): void;
35
+ }
36
+ export declare class NullableBaseAtom<T> extends BaseAtom<T> {
37
+ constructor(_value?: T | Observable<T>);
38
+ get<K extends keyof T>(key: K): (T extends (infer W)[] ? T[number] : T extends {
39
+ [key in keyof T]: infer W;
40
+ } ? T[keyof T] : undefined) | undefined;
36
41
  }
37
42
  export declare class ArrayAtom<T> extends ReadOnlyAtom<T[]> {
38
- constructor(initialValue: T[]);
43
+ constructor(initialValue?: T[]);
39
44
  push(nextVal: T): void;
40
45
  }
41
- export declare class ObjectAtom<T extends {
42
- [key in K]: V;
43
- }, K extends string | number | symbol = keyof T, V = T[K]> extends ReadOnlyAtom<T> {
44
- set(nextKey: K, nextValue: V): void;
45
- }
46
+ export declare function Atom<T extends any[]>(value?: Observable<T>): ArrayAtom<T[number]>;
46
47
  export declare function Atom<T>(value: T extends {
48
+ [key in keyof T]: infer V;
49
+ } ? Observable<T> : never): BaseAtom<T>;
50
+ export declare function Atom<T>(value?: T extends {
51
+ [key in keyof T]: infer V;
52
+ } ? Observable<T> : never): NullableBaseAtom<T>;
53
+ export declare function Atom<T>(value?: T extends {
47
54
  [key: string]: infer V;
48
55
  } | any[] ? never : Observable<T>): BaseAtom<T>;
49
- export declare function Atom<T extends any[]>(value: Observable<T>): ArrayAtom<T[number]>;
50
- export declare function Atom<T>(value: T extends {
51
- [key in keyof T]: infer V;
52
- } ? Observable<T> : never): ObjectAtom<T>;
53
- export declare function Atom<T extends any[]>(value: T): ArrayAtom<T[number]>;
56
+ export declare function Atom<T>(value?: T extends {
57
+ [key: string]: infer V;
58
+ } | any[] ? never : Observable<T>): NullableBaseAtom<T>;
59
+ export declare function Atom<T extends any[]>(value?: T): ArrayAtom<T[number]>;
60
+ export declare function Atom<T extends {
61
+ [key: string]: T[keyof T];
62
+ }>(value: T): BaseAtom<T>;
54
63
  export declare function Atom<T extends {
55
64
  [key: string]: T[keyof T];
56
- }>(value: T): ObjectAtom<T>;
65
+ }>(value?: T): NullableBaseAtom<T>;
57
66
  export declare function Atom<T>(value: T): BaseAtom<T>;
67
+ export declare function Atom<T>(value?: T): NullableBaseAtom<T>;
58
68
  export declare function Atom<T>(value: T, readOnly?: boolean): ReadOnlyAtom<T>;
59
69
  export declare namespace Atom {
60
70
  var combine: <A extends readonly unknown[]>(...atoms_0: AtomTuple<A>) => ReadOnlyAtom<A>;
@@ -1 +1 @@
1
- {"version":3,"file":"Atom.d.ts","sourceRoot":"","sources":["../src/Atom.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAKf,UAAU,EACV,gBAAgB,EAChB,YAAY,EACb,MAAM,MAAM,CAAC;AAGd,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;KACxB,CAAC,IAAI,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACnC,CAAC;AAEF,qBAAa,YAAY,CAAC,CAAC;IACzB,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;IAE/B,OAAO,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,CAA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CAAA;CAAE,EAC1D,KAAK,EAAE,CAAC,GACP,QAAQ,CAAC,CAAC,CAAC,CAAC;AAGf,wBAAgB,IAAI,CAAC,CAAC,SAAS;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;CAAE,EAC1D,KAAK,CAAC,EAAE,CAAC,GACR,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAGvB,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;AAG/C,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAGxD,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;yBAAvD,IAAI"}
package/dist/index.cjs.js CHANGED
@@ -29,6 +29,12 @@ function _setPrototypeOf(o, p) {
29
29
  };
30
30
  return _setPrototypeOf(o, p);
31
31
  }
32
+ function _assertThisInitialized(self) {
33
+ if (self === void 0) {
34
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
35
+ }
36
+ return self;
37
+ }
32
38
  function _unsupportedIterableToArray(o, minLen) {
33
39
  if (!o) return;
34
40
  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
@@ -107,7 +113,7 @@ var ReadOnlyAtom = /*#__PURE__*/function () {
107
113
  };
108
114
  _proto.get = function get(key) {
109
115
  var val = this.value();
110
- return val[key];
116
+ return val == null ? void 0 : val[key];
111
117
  };
112
118
  _proto.select = function select(key) {
113
119
  var newObs = this._behavior$.pipe(rxjs.distinctUntilKeyChanged(key), rxjs.map(function (k) {
@@ -124,22 +130,53 @@ var BaseAtom = /*#__PURE__*/function (_ReadOnlyAtom) {
124
130
  return _ReadOnlyAtom.apply(this, arguments) || this;
125
131
  }
126
132
  var _proto2 = BaseAtom.prototype;
127
- _proto2.set = function set(nextVal) {
133
+ _proto2.next = function next(nextVal) {
128
134
  this._behavior$.next(nextVal);
129
135
  };
136
+ _proto2.set = function set(nextKey, nextValue) {
137
+ var _extends2;
138
+ this._behavior$.next(_extends({}, this._behavior$.getValue(), (_extends2 = {}, _extends2[nextKey] = nextValue, _extends2)));
139
+ };
130
140
  return BaseAtom;
131
141
  }(ReadOnlyAtom);
142
+ var NullableBaseAtom = /*#__PURE__*/function (_BaseAtom) {
143
+ _inheritsLoose(NullableBaseAtom, _BaseAtom);
144
+ function NullableBaseAtom(_value) {
145
+ var _this2;
146
+ if (_value != null) {
147
+ _this2 = _BaseAtom.call(this, _value) || this;
148
+ } else {
149
+ // @ts-ignore
150
+ _this2 = _BaseAtom.call(this, undefined) || this;
151
+ }
152
+ return _assertThisInitialized(_this2);
153
+ }
154
+
155
+ // @ts-ignore
156
+ var _proto3 = NullableBaseAtom.prototype;
157
+ _proto3.get = function get(key) {
158
+ return _BaseAtom.prototype.get.call(this, key);
159
+ };
160
+ return NullableBaseAtom;
161
+ }(BaseAtom);
132
162
  var ArrayAtom = /*#__PURE__*/function (_ReadOnlyAtom2) {
133
163
  _inheritsLoose(ArrayAtom, _ReadOnlyAtom2);
134
164
  function ArrayAtom(initialValue) {
135
- return _ReadOnlyAtom2.call(this, initialValue) || this;
165
+ var _this3;
166
+ if (initialValue) {
167
+ _this3 = _ReadOnlyAtom2.call(this, initialValue) || this;
168
+ } else {
169
+ _this3 = _ReadOnlyAtom2.call(this, []) || this;
170
+ }
171
+ return _assertThisInitialized(_this3);
136
172
  }
137
- var _proto3 = ArrayAtom.prototype;
138
- _proto3.push = function push(nextVal) {
173
+ var _proto4 = ArrayAtom.prototype;
174
+ _proto4.push = function push(nextVal) {
139
175
  this._behavior$.next([].concat(this._behavior$.getValue(), [nextVal]));
140
176
  };
141
177
  return ArrayAtom;
142
178
  }(ReadOnlyAtom);
179
+
143
180
  //
144
181
  // export class ReadOnlyObjectAtom<
145
182
  // T extends {
@@ -171,29 +208,37 @@ var ArrayAtom = /*#__PURE__*/function (_ReadOnlyAtom2) {
171
208
  // : BaseAtom<T>;
172
209
  // }
173
210
  // }
174
-
175
- var ObjectAtom = /*#__PURE__*/function (_ReadOnlyAtom3) {
176
- _inheritsLoose(ObjectAtom, _ReadOnlyAtom3);
177
- function ObjectAtom() {
178
- return _ReadOnlyAtom3.apply(this, arguments) || this;
179
- }
180
- var _proto4 = ObjectAtom.prototype;
181
- _proto4.set = function set(nextKey, nextValue) {
182
- var _extends2;
183
- this._behavior$.next(_extends({}, this._behavior$.getValue(), (_extends2 = {}, _extends2[nextKey] = nextValue, _extends2)));
184
- };
185
- return ObjectAtom;
186
- }(ReadOnlyAtom);
211
+ //
212
+ // export class ObjectAtom<
213
+ // T extends
214
+ // | {
215
+ // [key in K]: V;
216
+ // }
217
+ // | null,
218
+ // K extends string | number | symbol = keyof T,
219
+ // V = T extends { [key in K]: infer W } ? T[K] : null
220
+ // > extends ReadOnlyAtom<T> {
221
+ // set(nextKey: K, nextValue: V) {
222
+ // this._behavior$.next({
223
+ // ...this._behavior$.getValue(),
224
+ // [nextKey]: nextValue,
225
+ // });
226
+ // }
227
+ // }
187
228
 
188
229
  // catch-all for developers
189
230
  // export type AnyAtom<T> = BaseAtom<T> | ArrayAtom<T> | ObjectAtom<T>;
190
231
 
191
- // observable type (primitive)
192
232
  // observable<array> type
193
233
  // observable<object> type
234
+ // nullable observable<object> type
235
+ // observable type (primitive)
236
+ // nullable observable type (primitive)
194
237
  // array type
195
238
  // object type
239
+ // nullable (unitialized) object type
196
240
  // primitive type
241
+ // nullable (unitialized) primitive type
197
242
  // readonly type
198
243
  // function definition
199
244
  function Atom(_value, readOnly) {
@@ -205,8 +250,8 @@ function Atom(_value, readOnly) {
205
250
  atom = new ReadOnlyAtom(_value);
206
251
  } else if (Array.isArray(_value)) {
207
252
  atom = new ArrayAtom(_value); // For arrays
208
- } else if (typeof _value === "object" && _value !== null) {
209
- atom = new ObjectAtom(_value); // For objects
253
+ } else if (_value == null) {
254
+ atom = new NullableBaseAtom();
210
255
  } else {
211
256
  atom = new BaseAtom(_value); // For other types
212
257
  }
@@ -254,17 +299,16 @@ function useSelectAtom(atom, key) {
254
299
  return value;
255
300
  }
256
301
 
257
- function useHydrateAtoms(values) {
258
- react.useEffect(function () {
259
- hydrateAtoms(values);
260
- }, []);
261
- }
302
+ var hydratedAtomsSet = new WeakSet();
262
303
  function hydrateAtoms(values) {
263
304
  for (var _iterator = _createForOfIteratorHelperLoose(values), _step; !(_step = _iterator()).done;) {
264
305
  var _step$value = _step.value,
265
306
  atom = _step$value[0],
266
307
  value = _step$value[1];
267
- atom._behavior$.next(value);
308
+ if (!hydratedAtomsSet.has(atom)) {
309
+ hydratedAtomsSet.add(atom);
310
+ atom._behavior$.next(value);
311
+ }
268
312
  }
269
313
  }
270
314
 
@@ -274,5 +318,4 @@ exports.Atom = Atom;
274
318
  exports.Signal = Signal;
275
319
  exports.hydrateAtoms = hydrateAtoms;
276
320
  exports.useAtom = useAtom;
277
- exports.useHydrateAtoms = useHydrateAtoms;
278
321
  exports.useSelectAtom = useSelectAtom;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { Atom } from "./Atom";
2
2
  export { useAtom } from "./useAtom";
3
3
  export { useSelectAtom } from "./useSelectAtom";
4
- export { hydrateAtoms, useHydrateAtoms } from "./useHydrateAtoms";
4
+ export { hydrateAtoms } from "./useHydrateAtoms";
5
5
  export { Signal } from "./Signal";
6
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,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAClE,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,mBAAmB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
@@ -27,6 +27,12 @@ var chemicalRx = (function (exports, rxjs, react) {
27
27
  };
28
28
  return _setPrototypeOf(o, p);
29
29
  }
30
+ function _assertThisInitialized(self) {
31
+ if (self === void 0) {
32
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
33
+ }
34
+ return self;
35
+ }
30
36
  function _unsupportedIterableToArray(o, minLen) {
31
37
  if (!o) return;
32
38
  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
@@ -105,7 +111,7 @@ var chemicalRx = (function (exports, rxjs, react) {
105
111
  };
106
112
  _proto.get = function get(key) {
107
113
  var val = this.value();
108
- return val[key];
114
+ return val == null ? void 0 : val[key];
109
115
  };
110
116
  _proto.select = function select(key) {
111
117
  var newObs = this._behavior$.pipe(rxjs.distinctUntilKeyChanged(key), rxjs.map(function (k) {
@@ -122,22 +128,53 @@ var chemicalRx = (function (exports, rxjs, react) {
122
128
  return _ReadOnlyAtom.apply(this, arguments) || this;
123
129
  }
124
130
  var _proto2 = BaseAtom.prototype;
125
- _proto2.set = function set(nextVal) {
131
+ _proto2.next = function next(nextVal) {
126
132
  this._behavior$.next(nextVal);
127
133
  };
134
+ _proto2.set = function set(nextKey, nextValue) {
135
+ var _extends2;
136
+ this._behavior$.next(_extends({}, this._behavior$.getValue(), (_extends2 = {}, _extends2[nextKey] = nextValue, _extends2)));
137
+ };
128
138
  return BaseAtom;
129
139
  }(ReadOnlyAtom);
140
+ var NullableBaseAtom = /*#__PURE__*/function (_BaseAtom) {
141
+ _inheritsLoose(NullableBaseAtom, _BaseAtom);
142
+ function NullableBaseAtom(_value) {
143
+ var _this2;
144
+ if (_value != null) {
145
+ _this2 = _BaseAtom.call(this, _value) || this;
146
+ } else {
147
+ // @ts-ignore
148
+ _this2 = _BaseAtom.call(this, undefined) || this;
149
+ }
150
+ return _assertThisInitialized(_this2);
151
+ }
152
+
153
+ // @ts-ignore
154
+ var _proto3 = NullableBaseAtom.prototype;
155
+ _proto3.get = function get(key) {
156
+ return _BaseAtom.prototype.get.call(this, key);
157
+ };
158
+ return NullableBaseAtom;
159
+ }(BaseAtom);
130
160
  var ArrayAtom = /*#__PURE__*/function (_ReadOnlyAtom2) {
131
161
  _inheritsLoose(ArrayAtom, _ReadOnlyAtom2);
132
162
  function ArrayAtom(initialValue) {
133
- return _ReadOnlyAtom2.call(this, initialValue) || this;
163
+ var _this3;
164
+ if (initialValue) {
165
+ _this3 = _ReadOnlyAtom2.call(this, initialValue) || this;
166
+ } else {
167
+ _this3 = _ReadOnlyAtom2.call(this, []) || this;
168
+ }
169
+ return _assertThisInitialized(_this3);
134
170
  }
135
- var _proto3 = ArrayAtom.prototype;
136
- _proto3.push = function push(nextVal) {
171
+ var _proto4 = ArrayAtom.prototype;
172
+ _proto4.push = function push(nextVal) {
137
173
  this._behavior$.next([].concat(this._behavior$.getValue(), [nextVal]));
138
174
  };
139
175
  return ArrayAtom;
140
176
  }(ReadOnlyAtom);
177
+
141
178
  //
142
179
  // export class ReadOnlyObjectAtom<
143
180
  // T extends {
@@ -169,29 +206,37 @@ var chemicalRx = (function (exports, rxjs, react) {
169
206
  // : BaseAtom<T>;
170
207
  // }
171
208
  // }
172
-
173
- var ObjectAtom = /*#__PURE__*/function (_ReadOnlyAtom3) {
174
- _inheritsLoose(ObjectAtom, _ReadOnlyAtom3);
175
- function ObjectAtom() {
176
- return _ReadOnlyAtom3.apply(this, arguments) || this;
177
- }
178
- var _proto4 = ObjectAtom.prototype;
179
- _proto4.set = function set(nextKey, nextValue) {
180
- var _extends2;
181
- this._behavior$.next(_extends({}, this._behavior$.getValue(), (_extends2 = {}, _extends2[nextKey] = nextValue, _extends2)));
182
- };
183
- return ObjectAtom;
184
- }(ReadOnlyAtom);
209
+ //
210
+ // export class ObjectAtom<
211
+ // T extends
212
+ // | {
213
+ // [key in K]: V;
214
+ // }
215
+ // | null,
216
+ // K extends string | number | symbol = keyof T,
217
+ // V = T extends { [key in K]: infer W } ? T[K] : null
218
+ // > extends ReadOnlyAtom<T> {
219
+ // set(nextKey: K, nextValue: V) {
220
+ // this._behavior$.next({
221
+ // ...this._behavior$.getValue(),
222
+ // [nextKey]: nextValue,
223
+ // });
224
+ // }
225
+ // }
185
226
 
186
227
  // catch-all for developers
187
228
  // export type AnyAtom<T> = BaseAtom<T> | ArrayAtom<T> | ObjectAtom<T>;
188
229
 
189
- // observable type (primitive)
190
230
  // observable<array> type
191
231
  // observable<object> type
232
+ // nullable observable<object> type
233
+ // observable type (primitive)
234
+ // nullable observable type (primitive)
192
235
  // array type
193
236
  // object type
237
+ // nullable (unitialized) object type
194
238
  // primitive type
239
+ // nullable (unitialized) primitive type
195
240
  // readonly type
196
241
  // function definition
197
242
  function Atom(_value, readOnly) {
@@ -203,8 +248,8 @@ var chemicalRx = (function (exports, rxjs, react) {
203
248
  atom = new ReadOnlyAtom(_value);
204
249
  } else if (Array.isArray(_value)) {
205
250
  atom = new ArrayAtom(_value); // For arrays
206
- } else if (typeof _value === "object" && _value !== null) {
207
- atom = new ObjectAtom(_value); // For objects
251
+ } else if (_value == null) {
252
+ atom = new NullableBaseAtom();
208
253
  } else {
209
254
  atom = new BaseAtom(_value); // For other types
210
255
  }
@@ -252,17 +297,16 @@ var chemicalRx = (function (exports, rxjs, react) {
252
297
  return value;
253
298
  }
254
299
 
255
- function useHydrateAtoms(values) {
256
- react.useEffect(function () {
257
- hydrateAtoms(values);
258
- }, []);
259
- }
300
+ var hydratedAtomsSet = new WeakSet();
260
301
  function hydrateAtoms(values) {
261
302
  for (var _iterator = _createForOfIteratorHelperLoose(values), _step; !(_step = _iterator()).done;) {
262
303
  var _step$value = _step.value,
263
304
  atom = _step$value[0],
264
305
  value = _step$value[1];
265
- atom._behavior$.next(value);
306
+ if (!hydratedAtomsSet.has(atom)) {
307
+ hydratedAtomsSet.add(atom);
308
+ atom._behavior$.next(value);
309
+ }
266
310
  }
267
311
  }
268
312
 
@@ -272,7 +316,6 @@ var chemicalRx = (function (exports, rxjs, react) {
272
316
  exports.Signal = Signal;
273
317
  exports.hydrateAtoms = hydrateAtoms;
274
318
  exports.useAtom = useAtom;
275
- exports.useHydrateAtoms = useHydrateAtoms;
276
319
  exports.useSelectAtom = useSelectAtom;
277
320
 
278
321
  return exports;
package/dist/index.js CHANGED
@@ -58,7 +58,7 @@ class ReadOnlyAtom {
58
58
  }
59
59
  get(key) {
60
60
  const val = this.value();
61
- return val[key];
61
+ return val == null ? void 0 : val[key];
62
62
  }
63
63
  select(key) {
64
64
  const newObs = this._behavior$.pipe(distinctUntilKeyChanged(key), map(k => k == null ? void 0 : k[key]));
@@ -67,18 +67,43 @@ class ReadOnlyAtom {
67
67
  }
68
68
  }
69
69
  class BaseAtom extends ReadOnlyAtom {
70
- set(nextVal) {
70
+ next(nextVal) {
71
71
  this._behavior$.next(nextVal);
72
72
  }
73
+ set(nextKey, nextValue) {
74
+ this._behavior$.next(_extends({}, this._behavior$.getValue(), {
75
+ [nextKey]: nextValue
76
+ }));
77
+ }
78
+ }
79
+ class NullableBaseAtom extends BaseAtom {
80
+ constructor(_value) {
81
+ if (_value != null) {
82
+ super(_value);
83
+ } else {
84
+ // @ts-ignore
85
+ super(undefined);
86
+ }
87
+ }
88
+
89
+ // @ts-ignore
90
+ get(key) {
91
+ return super.get(key);
92
+ }
73
93
  }
74
94
  class ArrayAtom extends ReadOnlyAtom {
75
95
  constructor(initialValue) {
76
- super(initialValue);
96
+ if (initialValue) {
97
+ super(initialValue);
98
+ } else {
99
+ super([]);
100
+ }
77
101
  }
78
102
  push(nextVal) {
79
103
  this._behavior$.next([...this._behavior$.getValue(), nextVal]);
80
104
  }
81
105
  }
106
+
82
107
  //
83
108
  // export class ReadOnlyObjectAtom<
84
109
  // T extends {
@@ -110,24 +135,37 @@ class ArrayAtom extends ReadOnlyAtom {
110
135
  // : BaseAtom<T>;
111
136
  // }
112
137
  // }
113
-
114
- class ObjectAtom extends ReadOnlyAtom {
115
- set(nextKey, nextValue) {
116
- this._behavior$.next(_extends({}, this._behavior$.getValue(), {
117
- [nextKey]: nextValue
118
- }));
119
- }
120
- }
138
+ //
139
+ // export class ObjectAtom<
140
+ // T extends
141
+ // | {
142
+ // [key in K]: V;
143
+ // }
144
+ // | null,
145
+ // K extends string | number | symbol = keyof T,
146
+ // V = T extends { [key in K]: infer W } ? T[K] : null
147
+ // > extends ReadOnlyAtom<T> {
148
+ // set(nextKey: K, nextValue: V) {
149
+ // this._behavior$.next({
150
+ // ...this._behavior$.getValue(),
151
+ // [nextKey]: nextValue,
152
+ // });
153
+ // }
154
+ // }
121
155
 
122
156
  // catch-all for developers
123
157
  // export type AnyAtom<T> = BaseAtom<T> | ArrayAtom<T> | ObjectAtom<T>;
124
158
 
125
- // observable type (primitive)
126
159
  // observable<array> type
127
160
  // observable<object> type
161
+ // nullable observable<object> type
162
+ // observable type (primitive)
163
+ // nullable observable type (primitive)
128
164
  // array type
129
165
  // object type
166
+ // nullable (unitialized) object type
130
167
  // primitive type
168
+ // nullable (unitialized) primitive type
131
169
  // readonly type
132
170
  // function definition
133
171
  function Atom(_value, readOnly = false) {
@@ -136,8 +174,8 @@ function Atom(_value, readOnly = false) {
136
174
  atom = new ReadOnlyAtom(_value);
137
175
  } else if (Array.isArray(_value)) {
138
176
  atom = new ArrayAtom(_value); // For arrays
139
- } else if (typeof _value === "object" && _value !== null) {
140
- atom = new ObjectAtom(_value); // For objects
177
+ } else if (_value == null) {
178
+ atom = new NullableBaseAtom();
141
179
  } else {
142
180
  atom = new BaseAtom(_value); // For other types
143
181
  }
@@ -176,17 +214,16 @@ function useSelectAtom(atom, key) {
176
214
  return value;
177
215
  }
178
216
 
179
- function useHydrateAtoms(values) {
180
- useEffect(() => {
181
- hydrateAtoms(values);
182
- }, []);
183
- }
217
+ const hydratedAtomsSet = new WeakSet();
184
218
  function hydrateAtoms(values) {
185
219
  for (const [atom, value] of values) {
186
- atom._behavior$.next(value);
220
+ if (!hydratedAtomsSet.has(atom)) {
221
+ hydratedAtomsSet.add(atom);
222
+ atom._behavior$.next(value);
223
+ }
187
224
  }
188
225
  }
189
226
 
190
227
  function Signal() {}
191
228
 
192
- export { Atom, Signal, hydrateAtoms, useAtom, useHydrateAtoms, useSelectAtom };
229
+ export { Atom, Signal, hydrateAtoms, useAtom, useSelectAtom };
@@ -1,4 +1,3 @@
1
1
  import { BaseAtom } from "./Atom";
2
- export declare function useHydrateAtoms(values: readonly [BaseAtom<any>, any][]): void;
3
2
  export declare function hydrateAtoms(values: readonly [BaseAtom<any>, any][]): void;
4
3
  //# sourceMappingURL=useHydrateAtoms.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useHydrateAtoms.d.ts","sourceRoot":"","sources":["../src/useHydrateAtoms.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,QAItE;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,QAInE"}
1
+ {"version":3,"file":"useHydrateAtoms.d.ts","sourceRoot":"","sources":["../src/useHydrateAtoms.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAgB,MAAM,QAAQ,CAAC;AAIhD,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,QAOnE"}
@@ -1,5 +1,5 @@
1
- import { ObjectAtom } from "./Atom";
1
+ import { BaseAtom } from "./Atom";
2
2
  export declare function useSelectAtom<T extends {
3
3
  [key in K]: V;
4
- }, K extends keyof T, V = T[K]>(atom: ObjectAtom<T>, key: K): T[K];
4
+ }, K extends keyof T, V = T[K]>(atom: BaseAtom<T>, key: K): T[K];
5
5
  //# sourceMappingURL=useSelectAtom.d.ts.map
@@ -1 +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,CAAC,EACjB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EACR,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAcnC"}
1
+ {"version":3,"file":"useSelectAtom.d.ts","sourceRoot":"","sources":["../src/useSelectAtom.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,wBAAgB,aAAa,CAC3B,CAAC,SAAS;KACP,GAAG,IAAI,CAAC,GAAG,CAAC;CACd,EACD,CAAC,SAAS,MAAM,CAAC,EACjB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EACR,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAcjC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chem-rx",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "react state primitives powered by rx.js",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/Atom.ts CHANGED
@@ -151,7 +151,7 @@ export class ReadOnlyAtom<T> {
151
151
  ? T[keyof T]
152
152
  : undefined {
153
153
  const val = this.value() as T;
154
- return val[key] as T extends (infer W)[]
154
+ return val?.[key] as T extends (infer W)[]
155
155
  ? T[number]
156
156
  : T extends { [key in keyof T]: infer W }
157
157
  ? T[keyof T]
@@ -160,11 +160,7 @@ export class ReadOnlyAtom<T> {
160
160
 
161
161
  select<K extends keyof T>(
162
162
  key: K
163
- ): T[K] extends (infer W)[]
164
- ? ArrayAtom<W>
165
- : T[K] extends { [key: string | symbol]: infer W }
166
- ? ObjectAtom<T[K]>
167
- : BaseAtom<T[K]> {
163
+ ): T[K] extends (infer W)[] ? ArrayAtom<W> : BaseAtom<T[K]> {
168
164
  const newObs = this._behavior$.pipe(
169
165
  distinctUntilKeyChanged(key),
170
166
  map((k) => k?.[key])
@@ -172,27 +168,66 @@ export class ReadOnlyAtom<T> {
172
168
  // Can't get typescript to recognize the types here so I'm cheating
173
169
  return Atom(newObs) as unknown as T[K] extends (infer W)[]
174
170
  ? ArrayAtom<W>
175
- : T[K] extends { [key: string | symbol]: infer W }
176
- ? ObjectAtom<T[K]>
177
171
  : BaseAtom<T[K]>;
178
172
  }
179
173
  }
180
174
 
181
175
  export class BaseAtom<T> extends ReadOnlyAtom<T> {
182
- set(nextVal: T) {
176
+ next(nextVal: T) {
183
177
  this._behavior$.next(nextVal);
184
178
  }
179
+
180
+ set(nextKey: keyof T, nextValue: T[keyof T]) {
181
+ this._behavior$.next({
182
+ ...this._behavior$.getValue(),
183
+ [nextKey]: nextValue,
184
+ });
185
+ }
186
+ }
187
+
188
+ export class NullableBaseAtom<T> extends BaseAtom<T> {
189
+ constructor(_value?: T | Observable<T>) {
190
+ if (_value != null) {
191
+ super(_value);
192
+ } else {
193
+ // @ts-ignore
194
+ super(undefined);
195
+ }
196
+ }
197
+
198
+ // @ts-ignore
199
+ get<K extends keyof T>(
200
+ key: K
201
+ // key: T extends (infer W)[]
202
+ // ? number
203
+ // : T extends { [key in keyof T]: infer W }
204
+ // ? keyof T
205
+ // : undefined
206
+ ):
207
+ | (T extends (infer W)[]
208
+ ? T[number]
209
+ : T extends { [key in keyof T]: infer W }
210
+ ? T[keyof T]
211
+ : undefined)
212
+ | undefined {
213
+ return super.get(key);
214
+ }
185
215
  }
186
216
 
187
217
  export class ArrayAtom<T> extends ReadOnlyAtom<T[]> {
188
- constructor(initialValue: T[]) {
189
- super(initialValue);
218
+ constructor(initialValue?: T[]) {
219
+ if (initialValue) {
220
+ super(initialValue);
221
+ } else {
222
+ super([]);
223
+ }
190
224
  }
191
225
 
192
226
  push(nextVal: T) {
193
227
  this._behavior$.next([...this._behavior$.getValue(), nextVal]);
194
228
  }
195
229
  }
230
+
196
231
  //
197
232
  // export class ReadOnlyObjectAtom<
198
233
  // T extends {
@@ -224,33 +259,30 @@ export class ArrayAtom<T> extends ReadOnlyAtom<T[]> {
224
259
  // : BaseAtom<T>;
225
260
  // }
226
261
  // }
227
-
228
- export class ObjectAtom<
229
- T extends {
230
- [key in K]: V;
231
- },
232
- K extends string | number | symbol = keyof T,
233
- V = T[K]
234
- > extends ReadOnlyAtom<T> {
235
- set(nextKey: K, nextValue: V) {
236
- this._behavior$.next({
237
- ...this._behavior$.getValue(),
238
- [nextKey]: nextValue,
239
- });
240
- }
241
- }
262
+ //
263
+ // export class ObjectAtom<
264
+ // T extends
265
+ // | {
266
+ // [key in K]: V;
267
+ // }
268
+ // | null,
269
+ // K extends string | number | symbol = keyof T,
270
+ // V = T extends { [key in K]: infer W } ? T[K] : null
271
+ // > extends ReadOnlyAtom<T> {
272
+ // set(nextKey: K, nextValue: V) {
273
+ // this._behavior$.next({
274
+ // ...this._behavior$.getValue(),
275
+ // [nextKey]: nextValue,
276
+ // });
277
+ // }
278
+ // }
242
279
 
243
280
  // catch-all for developers
244
281
  // export type AnyAtom<T> = BaseAtom<T> | ArrayAtom<T> | ObjectAtom<T>;
245
282
 
246
- // observable type (primitive)
247
- export function Atom<T>(
248
- value: T extends { [key: string]: infer V } | any[] ? never : Observable<T>
249
- ): BaseAtom<T>;
250
-
251
283
  // observable<array> type
252
284
  export function Atom<T extends any[]>(
253
- value: Observable<T>
285
+ value?: Observable<T>
254
286
  ): ArrayAtom<T[number]>;
255
287
 
256
288
  // observable<object> type
@@ -260,19 +292,46 @@ export function Atom<T>(
260
292
  }
261
293
  ? Observable<T>
262
294
  : never
263
- ): ObjectAtom<T>;
295
+ ): BaseAtom<T>;
296
+
297
+ // nullable observable<object> type
298
+ export function Atom<T>(
299
+ value?: T extends {
300
+ [key in keyof T]: infer V;
301
+ }
302
+ ? Observable<T>
303
+ : never
304
+ ): NullableBaseAtom<T>;
305
+
306
+ // observable type (primitive)
307
+ export function Atom<T>(
308
+ value?: T extends { [key: string]: infer V } | any[] ? never : Observable<T>
309
+ ): BaseAtom<T>;
310
+
311
+ // nullable observable type (primitive)
312
+ export function Atom<T>(
313
+ value?: T extends { [key: string]: infer V } | any[] ? never : Observable<T>
314
+ ): NullableBaseAtom<T>;
264
315
 
265
316
  // array type
266
- export function Atom<T extends any[]>(value: T): ArrayAtom<T[number]>;
317
+ export function Atom<T extends any[]>(value?: T): ArrayAtom<T[number]>;
267
318
 
268
319
  // object type
269
320
  export function Atom<T extends { [key: string]: T[keyof T] }>(
270
321
  value: T
271
- ): ObjectAtom<T>;
322
+ ): BaseAtom<T>;
323
+
324
+ // nullable (unitialized) object type
325
+ export function Atom<T extends { [key: string]: T[keyof T] }>(
326
+ value?: T
327
+ ): NullableBaseAtom<T>;
272
328
 
273
329
  // primitive type
274
330
  export function Atom<T>(value: T): BaseAtom<T>;
275
331
 
332
+ // nullable (unitialized) primitive type
333
+ export function Atom<T>(value?: T): NullableBaseAtom<T>;
334
+
276
335
  // readonly type
277
336
  export function Atom<T>(value: T, readOnly?: boolean): ReadOnlyAtom<T>;
278
337
 
@@ -283,8 +342,8 @@ export function Atom<T>(_value: T, readOnly: boolean = false) {
283
342
  atom = new ReadOnlyAtom(_value);
284
343
  } else if (Array.isArray(_value)) {
285
344
  atom = new ArrayAtom<T>(_value); // For arrays
286
- } else if (typeof _value === "object" && _value !== null) {
287
- atom = new ObjectAtom<T>(_value); // For objects
345
+ } else if (_value == null) {
346
+ atom = new NullableBaseAtom();
288
347
  } else {
289
348
  atom = new BaseAtom(_value); // For other types
290
349
  }
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { Atom } from "./Atom";
2
2
  export { useAtom } from "./useAtom";
3
3
  export { useSelectAtom } from "./useSelectAtom";
4
- export { hydrateAtoms, useHydrateAtoms } from "./useHydrateAtoms";
4
+ export { hydrateAtoms } from "./useHydrateAtoms";
5
5
  export { Signal } from "./Signal";
@@ -1,14 +1,13 @@
1
1
  import { useEffect } from "react";
2
- import { BaseAtom } from "./Atom";
2
+ import { BaseAtom, ReadOnlyAtom } from "./Atom";
3
3
 
4
- export function useHydrateAtoms(values: readonly [BaseAtom<any>, any][]) {
5
- useEffect(() => {
6
- hydrateAtoms(values);
7
- }, []);
8
- }
4
+ const hydratedAtomsSet: WeakSet<ReadOnlyAtom<any>> = new WeakSet();
9
5
 
10
6
  export function hydrateAtoms(values: readonly [BaseAtom<any>, any][]) {
11
7
  for (const [atom, value] of values) {
12
- atom._behavior$.next(value);
8
+ if (!hydratedAtomsSet.has(atom)) {
9
+ hydratedAtomsSet.add(atom);
10
+ atom._behavior$.next(value);
11
+ }
13
12
  }
14
13
  }
@@ -1,5 +1,5 @@
1
1
  import { useEffect, useState } from "react";
2
- import { ObjectAtom } from "./Atom";
2
+ import { BaseAtom } from "./Atom";
3
3
 
4
4
  export function useSelectAtom<
5
5
  T extends {
@@ -7,7 +7,7 @@ export function useSelectAtom<
7
7
  },
8
8
  K extends keyof T,
9
9
  V = T[K]
10
- >(atom: ObjectAtom<T>, key: K): T[K] {
10
+ >(atom: BaseAtom<T>, key: K): T[K] {
11
11
  const [value, setValue] = useState<T[K]>(atom.get(key)!);
12
12
 
13
13
  useEffect(() => {
@@ -1,10 +1,4 @@
1
- import {
2
- ArrayAtom,
3
- Atom,
4
- BaseAtom,
5
- ObjectAtom,
6
- ReadOnlyAtom,
7
- } from "../src/Atom";
1
+ import { ArrayAtom, Atom, BaseAtom, ReadOnlyAtom } from "../src/Atom";
8
2
  import { BehaviorSubject, map } from "rxjs";
9
3
 
10
4
  test("Base Atom values test", () => {
@@ -12,7 +6,7 @@ test("Base Atom values test", () => {
12
6
  expect(atom instanceof BaseAtom).toBe(true);
13
7
  expect(atom.value()).toBe("aweofij");
14
8
 
15
- atom.set("apro");
9
+ atom.next("apro");
16
10
 
17
11
  expect(atom.value()).toBe("apro");
18
12
  });
@@ -31,7 +25,7 @@ test("Object Atom values test", () => {
31
25
  firstKey: "firstValue",
32
26
  secondKey: "secondValue",
33
27
  });
34
- expect(atom instanceof ObjectAtom).toBe(true);
28
+ expect(atom instanceof BaseAtom).toBe(true);
35
29
  expect(atom.value()["firstKey"]).toBe("firstValue");
36
30
 
37
31
  expect(atom.value()["secondKey"]).toBe("secondValue");
@@ -49,7 +43,10 @@ test("Object Atom get function test", () => {
49
43
  firstKey: "firstValue",
50
44
  secondKey: "secondValue",
51
45
  });
52
- expect(atom instanceof ObjectAtom).toBe(true);
46
+
47
+ expect(atom.get("firey")).toBe(undefined);
48
+
49
+ expect(atom instanceof BaseAtom).toBe(true);
53
50
  expect(atom.get("firstKey")).toBe("firstValue");
54
51
 
55
52
  expect(atom.get("secondKey")).toBe("secondValue");
@@ -71,7 +68,76 @@ test("Object Enum Atom test", () => {
71
68
  [testEnum.first]: "firstValue",
72
69
  [testEnum.second]: "secondValue",
73
70
  });
74
- expect(atom instanceof ObjectAtom).toBe(true);
71
+
72
+ // this should always be defined as a string
73
+ const kkk = atom.get(testEnum.first);
74
+ kkk.toString();
75
+
76
+ expect(atom instanceof BaseAtom).toBe(true);
77
+ expect(atom.get(testEnum.first)).toBe("firstValue");
78
+
79
+ expect(atom.get(testEnum.second)).toBe("secondValue");
80
+ atom.set(testEnum.second, "newSecondValue");
81
+ expect(atom.get(testEnum.second)).toBe("newSecondValue");
82
+ });
83
+
84
+ test("Optional keys Object Atom test", () => {
85
+ enum testEnum {
86
+ first,
87
+ second,
88
+ }
89
+ const atom = Atom<{
90
+ [testEnum.first]?: string;
91
+ [testEnum.second]?: string;
92
+ }>({
93
+ [testEnum.first]: "firstValue",
94
+ [testEnum.second]: "secondValue",
95
+ });
96
+
97
+ const kkk = atom.get(testEnum.first);
98
+ // @ts-expect-error this should be possibly undefined
99
+ kkk.toString();
100
+
101
+ expect(atom instanceof BaseAtom).toBe(true);
102
+ expect(atom.get(testEnum.first)).toBe("firstValue");
103
+
104
+ expect(atom.get(testEnum.second)).toBe("secondValue");
105
+ atom.set(testEnum.second, "newSecondValue");
106
+ expect(atom.get(testEnum.second)).toBe("newSecondValue");
107
+ });
108
+
109
+ test("Uninitialized Object Enum Atom test", () => {
110
+ enum testEnum {
111
+ first,
112
+ second,
113
+ }
114
+ const seedValue = {
115
+ [testEnum.first]: "firstValue",
116
+ [testEnum.second]: "secondValue",
117
+ };
118
+ const atom = Atom<{
119
+ [testEnum.first]: string;
120
+ [testEnum.second]: string;
121
+ }>();
122
+
123
+ const kkk = atom.get(testEnum.first);
124
+ // this should be possibly undefined at this point,
125
+ // so there should lbe type safety here
126
+ expect(() => {
127
+ // @ts-expect-error this should throw a type error
128
+ // because it should be possibly undefined
129
+ kkk.toString();
130
+ }).toThrow();
131
+
132
+ // atom.push({
133
+ // [testEnum.first]: "firstValue",
134
+ // [testEnum.second]: "secondValue",
135
+ // });
136
+ expect(atom instanceof BaseAtom).toBe(true);
137
+
138
+ expect(atom.get(testEnum.first)).toBe(undefined);
139
+ expect(atom.get(testEnum.second)).toBe(undefined);
140
+ atom.next(seedValue);
75
141
  expect(atom.get(testEnum.first)).toBe("firstValue");
76
142
 
77
143
  expect(atom.get(testEnum.second)).toBe("secondValue");
@@ -81,6 +147,9 @@ test("Object Enum Atom test", () => {
81
147
 
82
148
  test("Array Atom values test", () => {
83
149
  const atom = Atom<string[]>(["first"]);
150
+
151
+ expect(atom.get(10)).toBe(undefined);
152
+
84
153
  // this is not allowed
85
154
  // atom.push(1);
86
155
  expect(atom instanceof ArrayAtom).toBe(true);
@@ -139,7 +208,7 @@ test("Test derive update", () => {
139
208
 
140
209
  expect(derivedAtom.value()).toBe(9);
141
210
 
142
- atom.set(4);
211
+ atom.next(4);
143
212
  expect(derivedAtom.value()).toBe(16);
144
213
  });
145
214
 
@@ -199,6 +268,9 @@ test("Test combine example", () => {
199
268
  }
200
269
  }
201
270
 
271
+ const a: number[] = [1, 3, 4, 5];
272
+ const b = a[10];
273
+
202
274
  const pets = mary$.select("pets").get(0);
203
275
  expect(mary$.select("pets").value().length).toBe(2);
204
276
  expect(mary$.select("pets").get(0)).toHaveProperty("type");
@@ -251,7 +323,7 @@ test("Test select (simple)", () => {
251
323
  c: { c: "c" },
252
324
  });
253
325
 
254
- const selectedString: ObjectAtom<{ [key: string]: string }> =
326
+ const selectedString: BaseAtom<{ [key: string]: string }> =
255
327
  stringData.select("b");
256
328
 
257
329
  const normalizedOptionalStringData = Atom<{
@@ -280,9 +352,9 @@ test("Test select (simple)", () => {
280
352
 
281
353
  const sel3 = objObsAtom2.select("a");
282
354
 
283
- expect(selected instanceof ObjectAtom).toBe(true);
355
+ expect(selected instanceof BaseAtom).toBe(true);
284
356
 
285
- expect(selected instanceof ObjectAtom).toBe(true);
357
+ expect(selected instanceof BaseAtom).toBe(true);
286
358
 
287
359
  // const combined = Atom.combine(normalizedData, ids).derive(([normed, ids]) => {
288
360
  // return ids.map((id) => normed[id]);