@converse/skeletor 3.1.3 → 3.1.4
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/CHANGES.md +12 -0
- package/README.md +3 -2
- package/dist/skeletor.d.ts +3 -3
- package/dist/skeletor.esm.js +9 -9
- package/dist/skeletor.esm.js.map +1 -1
- package/dist/skeletor.js +9 -9
- package/dist/skeletor.js.map +1 -1
- package/dist/skeletor.min.js +3 -3
- package/dist/skeletor.node.js +9 -9
- package/dist/skeletor.node.mjs +9 -9
- package/package.json +1 -1
- package/src/collection.ts +5 -5
- package/src/model.ts +6 -6
package/dist/skeletor.node.mjs
CHANGED
|
@@ -11055,18 +11055,18 @@ class Model extends EventEmitterObject {
|
|
|
11055
11055
|
this.initialize.apply(this, arguments);
|
|
11056
11056
|
// Reset changed after initial set
|
|
11057
11057
|
this.changed = {};
|
|
11058
|
-
// When autoSync is on, `
|
|
11059
|
-
// uniformly `await model.
|
|
11058
|
+
// When autoSync is on, `hydrated` is always a Promise so callers can
|
|
11059
|
+
// uniformly `await model.hydrated`. It only hydrates from storage when
|
|
11060
11060
|
// there's something to load (storage configured and the model isn't new);
|
|
11061
11061
|
// otherwise it's already ready and resolves immediately.
|
|
11062
11062
|
if (this.autoSync) {
|
|
11063
11063
|
if (getStorage(this) && !this.isNew()) {
|
|
11064
11064
|
__classPrivateFieldSet(this, _Model_state, 'hydrating', "f");
|
|
11065
|
-
this.
|
|
11065
|
+
this.hydrated = __classPrivateFieldGet(this, _Model_instances, "m", _Model_hydrate).call(this);
|
|
11066
11066
|
}
|
|
11067
11067
|
else {
|
|
11068
11068
|
__classPrivateFieldSet(this, _Model_state, 'ready', "f");
|
|
11069
|
-
this.
|
|
11069
|
+
this.hydrated = Promise.resolve();
|
|
11070
11070
|
}
|
|
11071
11071
|
}
|
|
11072
11072
|
else {
|
|
@@ -11239,7 +11239,7 @@ class Model extends EventEmitterObject {
|
|
|
11239
11239
|
// Guard must come after arg normalization: when called as set(obj, opts),
|
|
11240
11240
|
// fromStorage lives in `val` (second arg), not `options` (third arg).
|
|
11241
11241
|
if (this.autoSync && __classPrivateFieldGet(this, _Model_state, "f") === 'hydrating' && !options.fromStorage) {
|
|
11242
|
-
throw new Error(`Skeletor: set() called on an autoSync model before
|
|
11242
|
+
throw new Error(`Skeletor: set() called on an autoSync model before hydration resolved. Await model.hydrated first.`);
|
|
11243
11243
|
}
|
|
11244
11244
|
// Run validation.
|
|
11245
11245
|
if (!this._validate(attrs, options))
|
|
@@ -11679,11 +11679,11 @@ class Collection extends EventEmitterObject {
|
|
|
11679
11679
|
if (models)
|
|
11680
11680
|
this.reset(models, Object.assign({ silent: true }, options));
|
|
11681
11681
|
this[Symbol.iterator] = this.values;
|
|
11682
|
-
// When autoSync is on, `
|
|
11683
|
-
// uniformly `await collection.
|
|
11682
|
+
// When autoSync is on, `hydrated` is always a Promise so callers can
|
|
11683
|
+
// uniformly `await collection.hydrated`; it resolves immediately when
|
|
11684
11684
|
// there's no storage to hydrate from.
|
|
11685
11685
|
if (this.autoSync) {
|
|
11686
|
-
this.
|
|
11686
|
+
this.hydrated = getStorage(this) ? __classPrivateFieldGet(this, _Collection_instances, "m", _Collection_hydrate).call(this) : Promise.resolve();
|
|
11687
11687
|
}
|
|
11688
11688
|
}
|
|
11689
11689
|
get comparator() {
|
|
@@ -11715,7 +11715,7 @@ class Collection extends EventEmitterObject {
|
|
|
11715
11715
|
}
|
|
11716
11716
|
/**
|
|
11717
11717
|
* Override to return `true` to automatically load the collection from
|
|
11718
|
-
* storage on construction. Await `
|
|
11718
|
+
* storage on construction. Await `hydrated` to know when hydration
|
|
11719
11719
|
* is complete.
|
|
11720
11720
|
*
|
|
11721
11721
|
* Note: collection `autoSync` is hydrate-only. Unlike `Model`, it does
|
package/package.json
CHANGED
package/src/collection.ts
CHANGED
|
@@ -40,7 +40,7 @@ export class Collection<T extends Model = Model> extends EventEmitterObject {
|
|
|
40
40
|
_storage?: PersistentStorage;
|
|
41
41
|
_comparator?: Comparator<T>;
|
|
42
42
|
_url: string = '';
|
|
43
|
-
|
|
43
|
+
hydrated?: Promise<void>;
|
|
44
44
|
models: T[];
|
|
45
45
|
protected _byId: Record<string, T>;
|
|
46
46
|
protected _model?: new (attributes?: Partial<ModelAttributes>, options?: ModelOptions) => T;
|
|
@@ -61,11 +61,11 @@ export class Collection<T extends Model = Model> extends EventEmitterObject {
|
|
|
61
61
|
if (models) this.reset(models, Object.assign({ silent: true }, options));
|
|
62
62
|
|
|
63
63
|
this[Symbol.iterator] = this.values;
|
|
64
|
-
// When autoSync is on, `
|
|
65
|
-
// uniformly `await collection.
|
|
64
|
+
// When autoSync is on, `hydrated` is always a Promise so callers can
|
|
65
|
+
// uniformly `await collection.hydrated`; it resolves immediately when
|
|
66
66
|
// there's no storage to hydrate from.
|
|
67
67
|
if (this.autoSync) {
|
|
68
|
-
this.
|
|
68
|
+
this.hydrated = getStorage(this) ? this.#hydrate() : Promise.resolve();
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -104,7 +104,7 @@ export class Collection<T extends Model = Model> extends EventEmitterObject {
|
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
106
|
* Override to return `true` to automatically load the collection from
|
|
107
|
-
* storage on construction. Await `
|
|
107
|
+
* storage on construction. Await `hydrated` to know when hydration
|
|
108
108
|
* is complete.
|
|
109
109
|
*
|
|
110
110
|
* Note: collection `autoSync` is hydrate-only. Unlike `Model`, it does
|
package/src/model.ts
CHANGED
|
@@ -58,7 +58,7 @@ export class Model<T extends ModelAttributes = ModelAttributes> extends EventEmi
|
|
|
58
58
|
cid: string;
|
|
59
59
|
collection?: Collection;
|
|
60
60
|
id: string | number;
|
|
61
|
-
|
|
61
|
+
hydrated?: Promise<void>;
|
|
62
62
|
validationError: string | number | null = null;
|
|
63
63
|
|
|
64
64
|
/**
|
|
@@ -102,17 +102,17 @@ export class Model<T extends ModelAttributes = ModelAttributes> extends EventEmi
|
|
|
102
102
|
// Reset changed after initial set
|
|
103
103
|
this.changed = {};
|
|
104
104
|
|
|
105
|
-
// When autoSync is on, `
|
|
106
|
-
// uniformly `await model.
|
|
105
|
+
// When autoSync is on, `hydrated` is always a Promise so callers can
|
|
106
|
+
// uniformly `await model.hydrated`. It only hydrates from storage when
|
|
107
107
|
// there's something to load (storage configured and the model isn't new);
|
|
108
108
|
// otherwise it's already ready and resolves immediately.
|
|
109
109
|
if (this.autoSync) {
|
|
110
110
|
if (getStorage(this) && !this.isNew()) {
|
|
111
111
|
this.#state = 'hydrating';
|
|
112
|
-
this.
|
|
112
|
+
this.hydrated = this.#hydrate();
|
|
113
113
|
} else {
|
|
114
114
|
this.#state = 'ready';
|
|
115
|
-
this.
|
|
115
|
+
this.hydrated = Promise.resolve();
|
|
116
116
|
}
|
|
117
117
|
} else {
|
|
118
118
|
this.#state = 'ready';
|
|
@@ -347,7 +347,7 @@ export class Model<T extends ModelAttributes = ModelAttributes> extends EventEmi
|
|
|
347
347
|
// fromStorage lives in `val` (second arg), not `options` (third arg).
|
|
348
348
|
if (this.autoSync && this.#state === 'hydrating' && !options.fromStorage) {
|
|
349
349
|
throw new Error(
|
|
350
|
-
`Skeletor: set() called on an autoSync model before
|
|
350
|
+
`Skeletor: set() called on an autoSync model before hydration resolved. Await model.hydrated first.`,
|
|
351
351
|
);
|
|
352
352
|
}
|
|
353
353
|
|