native-document 1.0.188 → 1.0.190
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "native-document",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.190",
|
|
4
4
|
"description": "A reactive JavaScript framework that preserves native DOM simplicity without sacrificing modern features",
|
|
5
5
|
"author": "AfroCodeur <https://github.com/afrocodeur>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -176,6 +176,19 @@ Observable.computed = function(callback, dependencies = []) {
|
|
|
176
176
|
};
|
|
177
177
|
ObservableItem.computed = Observable.computed;
|
|
178
178
|
|
|
179
|
+
Observable.auto = (value) => {
|
|
180
|
+
if(value == null) {
|
|
181
|
+
return new ObservableItem(value);
|
|
182
|
+
}
|
|
183
|
+
if(Validator.isArray(value)) {
|
|
184
|
+
return new ObservableArray(value);
|
|
185
|
+
} else if(typeof value === 'object') {
|
|
186
|
+
return new ObservableObject(value);
|
|
187
|
+
}
|
|
188
|
+
return new ObservableItem(value);
|
|
189
|
+
};
|
|
190
|
+
ObservableItem.auto = Observable.auto;
|
|
191
|
+
|
|
179
192
|
|
|
180
193
|
Observable.init = function(initialValue, configs = null) {
|
|
181
194
|
return new ObservableObject(initialValue, configs);
|
|
@@ -290,7 +290,7 @@ ObservableArray.prototype.populateAndRender = function(iteration, callback) {
|
|
|
290
290
|
*/
|
|
291
291
|
ObservableArray.prototype.where = function(predicates, dependencies = null) {
|
|
292
292
|
if(typeof predicates === 'function') {
|
|
293
|
-
predicates = { _: predicates, dependencies };
|
|
293
|
+
predicates = { _: { callback: predicates, dependencies} };
|
|
294
294
|
}
|
|
295
295
|
const sourceArray = this;
|
|
296
296
|
const observableDependencies = [sourceArray];
|
|
@@ -59,6 +59,7 @@ Object.defineProperty(ObservableItem.prototype, '$value', {
|
|
|
59
59
|
ObservableItem.prototype.__$Observable = true;
|
|
60
60
|
ObservableItem.prototype.__$isObservable = true;
|
|
61
61
|
ObservableItem.computed = () => {};
|
|
62
|
+
ObservableItem.auto = () => {};
|
|
62
63
|
|
|
63
64
|
const DEFAULT_OPERATIONS = {};
|
|
64
65
|
const noneTrigger = function() {};
|
|
@@ -22,16 +22,7 @@ export const ObservableObject = function(target, configs) {
|
|
|
22
22
|
this.configs = configs;
|
|
23
23
|
|
|
24
24
|
for(const key in target) {
|
|
25
|
-
|
|
26
|
-
Object.defineProperty(this, key, {
|
|
27
|
-
get: () => this.$observables[key],
|
|
28
|
-
set: (value) => {
|
|
29
|
-
this.$observables[key].set(value);
|
|
30
|
-
},
|
|
31
|
-
configurable: true,
|
|
32
|
-
enumerable: true,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
25
|
+
this.$addKey(key);
|
|
35
26
|
}
|
|
36
27
|
|
|
37
28
|
this.$load(target);
|
|
@@ -60,6 +51,19 @@ Object.defineProperty(ObservableObject, '$value', {
|
|
|
60
51
|
ObservableObject.prototype.__$isObservableObject = true;
|
|
61
52
|
ObservableObject.prototype.__isProxy__ = true;
|
|
62
53
|
|
|
54
|
+
ObservableObject.prototype.$addKey = function(key) {
|
|
55
|
+
if(!Object.hasOwn(this, key)) {
|
|
56
|
+
Object.defineProperty(this, key, {
|
|
57
|
+
get: () => this.$observables[key],
|
|
58
|
+
set: (value) => {
|
|
59
|
+
this.$observables[key].set(value);
|
|
60
|
+
},
|
|
61
|
+
configurable: true,
|
|
62
|
+
enumerable: true,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
63
67
|
/**
|
|
64
68
|
* Initialises (or reinitialize) the internal observables map from a plain object.
|
|
65
69
|
* Called automatically in the constructor.
|
|
@@ -182,7 +186,7 @@ ObservableObject.prototype.set = function(newData) {
|
|
|
182
186
|
if(firstElementFromOriginalValue.__$isObservableObject) {
|
|
183
187
|
return new ObservableObject(item, configs);
|
|
184
188
|
}
|
|
185
|
-
return ObservableItem(item, configs);
|
|
189
|
+
return new ObservableItem(item, configs);
|
|
186
190
|
});
|
|
187
191
|
targetItem.set(newValues);
|
|
188
192
|
continue;
|
|
@@ -190,7 +194,9 @@ ObservableObject.prototype.set = function(newData) {
|
|
|
190
194
|
targetItem.set([...newValue]);
|
|
191
195
|
continue;
|
|
192
196
|
}
|
|
193
|
-
|
|
197
|
+
const value = ObservableItem.auto(newValue);
|
|
198
|
+
this.$observables[key] = value;
|
|
199
|
+
this.$addKey(key);
|
|
194
200
|
}
|
|
195
201
|
};
|
|
196
202
|
ObservableObject.prototype.$set = ObservableObject.prototype.set;
|
package/types/observable.d.ts
CHANGED
|
@@ -232,6 +232,7 @@ export type ObservableObject<T extends Record<string, any>> = ObservableItem<T>
|
|
|
232
232
|
$val(): T;
|
|
233
233
|
val(): T;
|
|
234
234
|
get(key: string): any;
|
|
235
|
+
only<K extends keyof T>(...properties: K[]): Pick<T, K>;
|
|
235
236
|
$get(key: string): any;
|
|
236
237
|
set(values: Partial<T>): void;
|
|
237
238
|
$set(values: Partial<T>): void;
|
|
@@ -319,6 +320,8 @@ export interface ObservableStatic {
|
|
|
319
320
|
object<T extends Record<string, any>>(value: T, configs?: ObservableConfig | null): ObservableObject<T>;
|
|
320
321
|
json<T extends Record<string, any>>(value: T, configs?: ObservableConfig | null): ObservableObject<T>;
|
|
321
322
|
|
|
323
|
+
auto<T>(value: T): ObservableArray<T>|ObservableObject<T>|ObservableItem<T>;
|
|
324
|
+
|
|
322
325
|
resource<T = any>(
|
|
323
326
|
fn: (...args: any[]) => Promise<T>,
|
|
324
327
|
dependencies?: ValidComputedDependencies,
|