@converse/skeletor 0.0.9 → 2.0.0
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/README.md +5 -89
- package/dist/skeletor.d.ts +764 -0
- package/dist/skeletor.js +7568 -7747
- package/dist/skeletor.min.js +6 -11
- package/package.json +46 -30
- package/src/{collection.js → collection.ts} +232 -271
- package/src/drivers/{sessionStorage.js → sessionStorage.ts} +81 -93
- package/src/{eventemitter.js → eventemitter.ts} +44 -59
- package/src/{helpers.js → helpers.ts} +56 -69
- package/src/index.ts +84 -0
- package/src/{listening.js → listening.ts} +32 -27
- package/src/{model.js → model.ts} +143 -162
- package/src/{storage.js → storage.ts} +92 -49
- package/src/types.ts +189 -0
- package/src/utils/{events.js → events.ts} +98 -48
- package/dist/skeletor.js.map +0 -1
- package/dist/skeletor.min.js.map +0 -1
- package/src/element.js +0 -238
- package/src/index.js +0 -47
- package/src/types/collection.d.ts +0 -366
- package/src/types/collection.d.ts.map +0 -1
- package/src/types/drivers/sessionStorage.d.ts +0 -37
- package/src/types/drivers/sessionStorage.d.ts.map +0 -1
- package/src/types/element.d.ts +0 -115
- package/src/types/element.d.ts.map +0 -1
- package/src/types/eventemitter.d.ts +0 -93
- package/src/types/eventemitter.d.ts.map +0 -1
- package/src/types/helpers.d.ts +0 -62
- package/src/types/helpers.d.ts.map +0 -1
- package/src/types/index.d.ts +0 -19
- package/src/types/index.d.ts.map +0 -1
- package/src/types/listening.d.ts +0 -40
- package/src/types/listening.d.ts.map +0 -1
- package/src/types/model.d.ts +0 -230
- package/src/types/model.d.ts.map +0 -1
- package/src/types/storage.d.ts +0 -35
- package/src/types/storage.d.ts.map +0 -1
- package/src/types/utils/events.d.ts +0 -28
- package/src/types/utils/events.d.ts.map +0 -1
|
@@ -0,0 +1,764 @@
|
|
|
1
|
+
import localForage from 'localforage';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare type ClassConstructor<T = any> = new (...args: any[]) => T;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
* If models tend to represent a single row of data, a Collection is
|
|
11
|
+
* more analogous to a table full of data ... or a small slice or page of that
|
|
12
|
+
* table, or a collection of rows that belong together for a particular reason
|
|
13
|
+
* -- all of the messages in this particular folder, all of the documents
|
|
14
|
+
* belonging to this particular author, and so on. Collections maintain
|
|
15
|
+
* indexes of their models, both in order, and for lookup by `id`.
|
|
16
|
+
*/
|
|
17
|
+
export declare class Collection<T extends Model = Model> extends EventEmitterObject {
|
|
18
|
+
[key: symbol]: () => CollectionIterator<T>;
|
|
19
|
+
_browserStorage?: Storage_2;
|
|
20
|
+
_comparator?: Comparator<T>;
|
|
21
|
+
_url: string;
|
|
22
|
+
models: T[];
|
|
23
|
+
protected _byId: Record<string, T>;
|
|
24
|
+
protected _model?: new (attributes?: Partial<ModelAttributes>, options?: ModelOptions) => T;
|
|
25
|
+
/**
|
|
26
|
+
* Create a new **Collection**, perhaps to contain a specific type of `model`.
|
|
27
|
+
* If a `comparator` is specified, the Collection will maintain
|
|
28
|
+
* its models in sort order, as they're added and removed.
|
|
29
|
+
*/
|
|
30
|
+
constructor(models?: T[] | ModelAttributes[] | T | ModelAttributes, options?: CollectionOptions<T>);
|
|
31
|
+
get comparator(): Comparator<T>;
|
|
32
|
+
set comparator(c: Comparator<T>);
|
|
33
|
+
set browserStorage(storage: Storage_2);
|
|
34
|
+
get browserStorage(): Storage_2 | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* The default model for a collection is just a **Model**.
|
|
37
|
+
* This should be overridden in most cases.
|
|
38
|
+
*/
|
|
39
|
+
get model(): new (attributes?: Partial<ModelAttributes>, options?: ModelOptions) => T | Model;
|
|
40
|
+
set model(model: new (attributes?: Partial<ModelAttributes>, options?: ModelOptions) => T);
|
|
41
|
+
get length(): number;
|
|
42
|
+
get url(): string;
|
|
43
|
+
set url(url: string);
|
|
44
|
+
/**
|
|
45
|
+
* preinitialize is an empty function by default. You can override it with a function
|
|
46
|
+
* or object. preinitialize will run before any instantiation logic is run in the Collection.
|
|
47
|
+
*/
|
|
48
|
+
preinitialize(..._args: any[]): void;
|
|
49
|
+
/**
|
|
50
|
+
* Initialize is an empty function by default. Override it with your own
|
|
51
|
+
* initialization logic.
|
|
52
|
+
*/
|
|
53
|
+
initialize(..._args: any[]): void;
|
|
54
|
+
/**
|
|
55
|
+
* The JSON representation of a Collection is an array of the
|
|
56
|
+
* models' attributes.
|
|
57
|
+
*/
|
|
58
|
+
toJSON(): any[];
|
|
59
|
+
sync(method: SyncOperation, model: Model | Collection<any>, options?: Options): any;
|
|
60
|
+
/**
|
|
61
|
+
* Add a model, or list of models to the set. `models` may be
|
|
62
|
+
* Models or raw JavaScript objects to be converted to Models, or any
|
|
63
|
+
* combination of the two.
|
|
64
|
+
*/
|
|
65
|
+
add(models: T[] | T | ModelAttributes | ModelAttributes[], options?: Options): T | T[];
|
|
66
|
+
/**
|
|
67
|
+
* Remove a model, or a list of models from the set.
|
|
68
|
+
*/
|
|
69
|
+
remove(models: T | ObjectWithId | (T | ObjectWithId)[], options?: Options): T | T[];
|
|
70
|
+
/**
|
|
71
|
+
* Update a collection by `set`-ing a new list of models, adding new ones,
|
|
72
|
+
* removing models that are no longer present, and merging models that
|
|
73
|
+
* already exist in the collection, as necessary. Similar to **Model#set**,
|
|
74
|
+
* the core operation for updating the data contained by the collection.
|
|
75
|
+
*/
|
|
76
|
+
set(models: T[] | T | ModelAttributes | ModelAttributes[], options?: Options): T | T[];
|
|
77
|
+
clearStore(options?: Options, filter?: (model: T) => boolean): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* When you have more items than you want to add or remove individually,
|
|
80
|
+
* you can reset the entire set with a new list of models, without firing
|
|
81
|
+
* any granular `add` or `remove` events. Fires `reset` when finished.
|
|
82
|
+
* Useful for bulk operations and optimizations.
|
|
83
|
+
*/
|
|
84
|
+
reset(models?: T[] | T | ModelAttributes | ModelAttributes[], options?: Options): T | T[];
|
|
85
|
+
/**
|
|
86
|
+
* Add a model to the end of the collection.
|
|
87
|
+
*/
|
|
88
|
+
push(model: T | ModelAttributes, options?: Options): T;
|
|
89
|
+
/**
|
|
90
|
+
* Remove a model from the end of the collection.
|
|
91
|
+
*/
|
|
92
|
+
pop(options?: Options): T | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Add a model to the beginning of the collection.
|
|
95
|
+
*/
|
|
96
|
+
unshift(model: T | ModelAttributes, options?: Options): T;
|
|
97
|
+
/**
|
|
98
|
+
* Remove a model from the beginning of the collection.
|
|
99
|
+
*/
|
|
100
|
+
shift(options?: Options): T | undefined;
|
|
101
|
+
/** Slice out a sub-array of models from the collection. */
|
|
102
|
+
slice(start?: number, end?: number): T[];
|
|
103
|
+
filter(callback: ((model: T) => boolean) | string | Partial<ModelAttributes>, thisArg?: any): T[];
|
|
104
|
+
every(pred: ((attrs: ModelAttributes) => boolean) | Options): boolean;
|
|
105
|
+
difference(values: T[]): T[];
|
|
106
|
+
max(): number;
|
|
107
|
+
min(): number;
|
|
108
|
+
drop(n?: number): T[];
|
|
109
|
+
some(pred: ((attrs: ModelAttributes) => boolean) | Options): boolean;
|
|
110
|
+
sortBy(iteratee: string | ((model: T) => any)): T[];
|
|
111
|
+
isEmpty(): boolean;
|
|
112
|
+
keyBy(iteratee: string | ((model: T) => string)): Record<string, T>;
|
|
113
|
+
each(callback: (model: T, index: number, array: T[]) => void, thisArg?: any): void;
|
|
114
|
+
forEach(callback: (model: T, index: number, array: T[]) => void, thisArg?: any): void;
|
|
115
|
+
includes(item: T): boolean;
|
|
116
|
+
size(): number;
|
|
117
|
+
countBy(f: string | ((model: T) => string) | Partial<ModelAttributes>): Record<string, number>;
|
|
118
|
+
groupBy(pred: string | ((model: T) => string | number)): Record<string, T[]>;
|
|
119
|
+
indexOf(model: T, fromIndex?: number): number;
|
|
120
|
+
findLastIndex(pred: ((model: T) => boolean) | string | Partial<ModelAttributes>, fromIndex?: number): number;
|
|
121
|
+
lastIndexOf(model: T, fromIndex?: number): number;
|
|
122
|
+
findIndex(pred: ((model: T) => boolean) | string | Partial<ModelAttributes>): number;
|
|
123
|
+
last(): T | undefined;
|
|
124
|
+
head(): T | undefined;
|
|
125
|
+
first(): T | undefined;
|
|
126
|
+
map<U>(cb: string | ((model: T) => U) | Partial<ModelAttributes>, thisArg?: any): U[];
|
|
127
|
+
reduce<U = T>(callback: (accumulator: U, model: T, index: number, array: T[]) => U, initialValue?: U): U | T;
|
|
128
|
+
reduceRight<U = T>(callback: (accumulator: U, model: T, index: number, array: T[]) => U, initialValue?: U): U | T;
|
|
129
|
+
toArray(): T[];
|
|
130
|
+
/**
|
|
131
|
+
* Get a model from the set by id, cid, model object with id or cid
|
|
132
|
+
* properties, or an attributes object that is transformed through modelId.
|
|
133
|
+
*/
|
|
134
|
+
get(obj?: string | number | ModelAttributes | T | null): T | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* Returns `true` if the model is in the collection.
|
|
137
|
+
*/
|
|
138
|
+
has(obj: string | number | ModelAttributes | T | null): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Get the model at the given index.
|
|
141
|
+
*/
|
|
142
|
+
at(index: number): T | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* Return models with matching attributes. Useful for simple cases of
|
|
145
|
+
* `filter`.
|
|
146
|
+
*/
|
|
147
|
+
where(attrs: ModelAttributes | Partial<ModelAttributes>, first?: boolean): T[] | T | undefined;
|
|
148
|
+
/**
|
|
149
|
+
* Return the first model with matching attributes. Useful for simple cases
|
|
150
|
+
* of `find`.
|
|
151
|
+
*/
|
|
152
|
+
findWhere(attrs: ModelAttributes): T | undefined;
|
|
153
|
+
find(predicate: ((model: T) => boolean) | Partial<ModelAttributes> | string, fromIndex?: number): T | undefined;
|
|
154
|
+
/**
|
|
155
|
+
* Force the collection to re-sort itself. You don't need to call this under
|
|
156
|
+
* normal circumstances, as the set will maintain sort order as each item
|
|
157
|
+
* is added.
|
|
158
|
+
*/
|
|
159
|
+
sort(options?: Options): this;
|
|
160
|
+
/**
|
|
161
|
+
* Pluck an attribute from each model in the collection.
|
|
162
|
+
*/
|
|
163
|
+
pluck(attr: string): any[];
|
|
164
|
+
/**
|
|
165
|
+
* Fetch the default set of models for this collection, resetting the
|
|
166
|
+
* collection when they arrive. If `reset: true` is passed, the response
|
|
167
|
+
* data will be passed through the `reset` method instead of `set`.
|
|
168
|
+
*/
|
|
169
|
+
fetch(options?: Options): Promise<any> | any;
|
|
170
|
+
/**
|
|
171
|
+
* Create a new instance of a model in this collection. Add the model to the
|
|
172
|
+
* collection immediately, unless `wait: true` is passed, in which case we
|
|
173
|
+
* wait for the server to agree.
|
|
174
|
+
*/
|
|
175
|
+
create(model: T | ModelAttributes, options?: Options): Promise<T> | T | false;
|
|
176
|
+
/**
|
|
177
|
+
* **parse** converts a response into a list of models to be added to the
|
|
178
|
+
* collection. The default implementation is just to pass it through.
|
|
179
|
+
*/
|
|
180
|
+
parse(resp: any, _options?: Options): any;
|
|
181
|
+
/**
|
|
182
|
+
* Define how to uniquely identify models in the collection.
|
|
183
|
+
*/
|
|
184
|
+
modelId(attrs: ModelAttributes): string | number | undefined;
|
|
185
|
+
/** Get an iterator of all models in this collection. */
|
|
186
|
+
values(): CollectionIterator<T>;
|
|
187
|
+
/**
|
|
188
|
+
* @public
|
|
189
|
+
* Enable for...of iteration over the collection.
|
|
190
|
+
*/
|
|
191
|
+
[Symbol.iterator]: () => CollectionIterator<T>;
|
|
192
|
+
/** Get an iterator of all model IDs in this collection. */
|
|
193
|
+
keys(): CollectionIterator<T>;
|
|
194
|
+
/** Get an iterator of all [ID, model] tuples in this collection. */
|
|
195
|
+
entries(): CollectionIterator<T>;
|
|
196
|
+
/**
|
|
197
|
+
* Private method to reset all internal state. Called when the collection
|
|
198
|
+
* is first initialized or reset.
|
|
199
|
+
*/
|
|
200
|
+
_reset(): void;
|
|
201
|
+
createModel(attrs: ModelAttributes, options?: Options): T;
|
|
202
|
+
/**
|
|
203
|
+
* Prepare a hash of attributes (or other model) to be added to this
|
|
204
|
+
* collection.
|
|
205
|
+
*/
|
|
206
|
+
_prepareModel(attrs: ModelAttributes | T, options?: Options): T | null;
|
|
207
|
+
/**
|
|
208
|
+
* Internal method called by both remove and set.
|
|
209
|
+
*/
|
|
210
|
+
_removeModels(models: (T | ObjectWithId)[], options?: Options): T[];
|
|
211
|
+
/**
|
|
212
|
+
* Method for checking whether an object should be considered a model for
|
|
213
|
+
* the purposes of adding to the collection.
|
|
214
|
+
*/
|
|
215
|
+
_isModel(model: any): model is T;
|
|
216
|
+
/**
|
|
217
|
+
* Internal method to create a model's ties to a collection.
|
|
218
|
+
*/
|
|
219
|
+
_addReference(model: T, _options?: Options): void;
|
|
220
|
+
/**
|
|
221
|
+
* Internal method to sever a model's ties to a collection.
|
|
222
|
+
*/
|
|
223
|
+
_removeReference(model: T, _options?: Options): void;
|
|
224
|
+
/**
|
|
225
|
+
* Internal method called every time a model in the set fires an event.
|
|
226
|
+
* Sets need to update their indexes when models change ids. All other
|
|
227
|
+
* events simply proxy through. "add" and "remove" events that originate
|
|
228
|
+
* in other collections are ignored.
|
|
229
|
+
*/
|
|
230
|
+
_onModelEvent(event: string, model: T, collection: Collection<T>, options?: Options): void;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* @public
|
|
235
|
+
*/
|
|
236
|
+
export declare class CollectionIterator<T extends Model> {
|
|
237
|
+
private _collection;
|
|
238
|
+
private _kind;
|
|
239
|
+
private _index;
|
|
240
|
+
/**
|
|
241
|
+
* A CollectionIterator implements JavaScript's Iterator protocol, allowing the
|
|
242
|
+
* use of `for of` loops in modern browsers and interoperation between
|
|
243
|
+
* Collection and other JavaScript functions and third-party libraries
|
|
244
|
+
* which can operate on Iterables.
|
|
245
|
+
*/
|
|
246
|
+
constructor(collection: Collection<T>, kind: number);
|
|
247
|
+
next(): IteratorResult<any>;
|
|
248
|
+
[Symbol.iterator](): IterableIterator<any>;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* @public
|
|
253
|
+
*/
|
|
254
|
+
export declare type CollectionOptions<T extends Model = Model> = Options & {
|
|
255
|
+
model?: new (attributes?: Partial<ModelAttributes>, options?: ModelOptions) => T;
|
|
256
|
+
comparator?: Comparator<T>;
|
|
257
|
+
previousModels?: Model[];
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* @public
|
|
262
|
+
*/
|
|
263
|
+
export declare type Comparator<T extends Model = Model> = string | boolean | ((a: T, b: T) => number) | ((a?: T) => string);
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* @public
|
|
267
|
+
*/
|
|
268
|
+
export declare type EventCallback = (...args: any[]) => void;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* @public
|
|
272
|
+
*/
|
|
273
|
+
export declare type EventCallbackMap = Record<string, EventCallback>;
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* @public
|
|
277
|
+
*/
|
|
278
|
+
export declare type EventContext = unknown;
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* @public
|
|
282
|
+
*/
|
|
283
|
+
export declare function EventEmitter<T extends ClassConstructor>(Base: T): {
|
|
284
|
+
new (...args: any[]): {
|
|
285
|
+
[x: string]: any;
|
|
286
|
+
_events?: EventHandlersMap;
|
|
287
|
+
_listeners?: EventListenerMap;
|
|
288
|
+
_listeningTo?: EventListenerMap;
|
|
289
|
+
_listenId?: string;
|
|
290
|
+
/**
|
|
291
|
+
* Bind an event to a `callback` function. Passing `"all"` will bind
|
|
292
|
+
* the callback to all events fired.
|
|
293
|
+
*/
|
|
294
|
+
on(name: string | EventCallbackMap, callback?: EventCallback | EventContext, context?: EventContext): /*elided*/ any;
|
|
295
|
+
/**
|
|
296
|
+
* Inversion-of-control versions of `on`. Tell *this* object to listen to
|
|
297
|
+
* an event in another object... keeping track of what it's listening to
|
|
298
|
+
* for easier unbinding later.
|
|
299
|
+
*/
|
|
300
|
+
listenTo(obj: ObjectListenedTo, name: string | EventCallbackMap, callback?: EventCallback): /*elided*/ any;
|
|
301
|
+
/**
|
|
302
|
+
* Remove one or many callbacks. If `context` is null, removes all
|
|
303
|
+
* callbacks with that function. If `callback` is null, removes all
|
|
304
|
+
* callbacks for the event. If `name` is null, removes all bound
|
|
305
|
+
* callbacks for all events.
|
|
306
|
+
*/
|
|
307
|
+
off(name?: string | EventCallbackMap | null, callback?: EventCallback | EventContext | null, context?: EventContext): /*elided*/ any;
|
|
308
|
+
/**
|
|
309
|
+
* Tell this object to stop listening to either specific events ... or
|
|
310
|
+
* to every object it's currently listening to.
|
|
311
|
+
*/
|
|
312
|
+
stopListening(obj?: any, name?: string | EventCallbackMap, callback?: EventCallback): /*elided*/ any;
|
|
313
|
+
/**
|
|
314
|
+
* Bind an event to only be triggered a single time. After the first time
|
|
315
|
+
* the callback is invoked, its listener will be removed. If multiple events
|
|
316
|
+
* are passed in using the space-separated syntax, the handler will fire
|
|
317
|
+
* once for each event, not once for a combination of all events.
|
|
318
|
+
*/
|
|
319
|
+
once(name: string | EventCallbackMap, callback?: EventCallback | EventContext, context?: EventContext): /*elided*/ any;
|
|
320
|
+
/**
|
|
321
|
+
* Inversion-of-control versions of `once`.
|
|
322
|
+
*/
|
|
323
|
+
listenToOnce(obj: any, name: string | EventCallbackMap, callback?: EventCallback): /*elided*/ any;
|
|
324
|
+
/**
|
|
325
|
+
* Trigger one or many events, firing all bound callbacks. Callbacks are
|
|
326
|
+
* passed the same arguments as `trigger` is, apart from the event name
|
|
327
|
+
* (unless you're listening on `"all"`, which will cause your callback to
|
|
328
|
+
* receive the true name of the event as the first argument).
|
|
329
|
+
*/
|
|
330
|
+
trigger(name: string, ...args: any[]): /*elided*/ any;
|
|
331
|
+
};
|
|
332
|
+
} & T;
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* @public
|
|
336
|
+
*/
|
|
337
|
+
export declare const EventEmitterObject: {
|
|
338
|
+
new (...args: any[]): {
|
|
339
|
+
[x: string]: any;
|
|
340
|
+
_events?: EventHandlersMap;
|
|
341
|
+
_listeners?: EventListenerMap;
|
|
342
|
+
_listeningTo?: EventListenerMap;
|
|
343
|
+
_listenId?: string;
|
|
344
|
+
/**
|
|
345
|
+
* Bind an event to a `callback` function. Passing `"all"` will bind
|
|
346
|
+
* the callback to all events fired.
|
|
347
|
+
*/
|
|
348
|
+
on(name: string | EventCallbackMap, callback?: EventCallback | EventContext, context?: EventContext): /*elided*/ any;
|
|
349
|
+
/**
|
|
350
|
+
* Inversion-of-control versions of `on`. Tell *this* object to listen to
|
|
351
|
+
* an event in another object... keeping track of what it's listening to
|
|
352
|
+
* for easier unbinding later.
|
|
353
|
+
*/
|
|
354
|
+
listenTo(obj: ObjectListenedTo, name: string | EventCallbackMap, callback?: EventCallback): /*elided*/ any;
|
|
355
|
+
/**
|
|
356
|
+
* Remove one or many callbacks. If `context` is null, removes all
|
|
357
|
+
* callbacks with that function. If `callback` is null, removes all
|
|
358
|
+
* callbacks for the event. If `name` is null, removes all bound
|
|
359
|
+
* callbacks for all events.
|
|
360
|
+
*/
|
|
361
|
+
off(name?: string | EventCallbackMap | null, callback?: EventCallback | EventContext | null, context?: EventContext): /*elided*/ any;
|
|
362
|
+
/**
|
|
363
|
+
* Tell this object to stop listening to either specific events ... or
|
|
364
|
+
* to every object it's currently listening to.
|
|
365
|
+
*/
|
|
366
|
+
stopListening(obj?: any, name?: string | EventCallbackMap, callback?: EventCallback): /*elided*/ any;
|
|
367
|
+
/**
|
|
368
|
+
* Bind an event to only be triggered a single time. After the first time
|
|
369
|
+
* the callback is invoked, its listener will be removed. If multiple events
|
|
370
|
+
* are passed in using the space-separated syntax, the handler will fire
|
|
371
|
+
* once for each event, not once for a combination of all events.
|
|
372
|
+
*/
|
|
373
|
+
once(name: string | EventCallbackMap, callback?: EventCallback | EventContext, context?: EventContext): /*elided*/ any;
|
|
374
|
+
/**
|
|
375
|
+
* Inversion-of-control versions of `once`.
|
|
376
|
+
*/
|
|
377
|
+
listenToOnce(obj: any, name: string | EventCallbackMap, callback?: EventCallback): /*elided*/ any;
|
|
378
|
+
/**
|
|
379
|
+
* Trigger one or many events, firing all bound callbacks. Callbacks are
|
|
380
|
+
* passed the same arguments as `trigger` is, apart from the event name
|
|
381
|
+
* (unless you're listening on `"all"`, which will cause your callback to
|
|
382
|
+
* receive the true name of the event as the first argument).
|
|
383
|
+
*/
|
|
384
|
+
trigger(name: string, ...args: any[]): /*elided*/ any;
|
|
385
|
+
};
|
|
386
|
+
} & ObjectConstructor;
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* @public
|
|
390
|
+
*/
|
|
391
|
+
export declare interface EventHandler {
|
|
392
|
+
callback: EventCallback;
|
|
393
|
+
context: any;
|
|
394
|
+
ctx: any;
|
|
395
|
+
listening?: ListeningType | null;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* @public
|
|
400
|
+
*/
|
|
401
|
+
export declare interface EventHandlersMap {
|
|
402
|
+
all?: EventHandler[];
|
|
403
|
+
[name: string]: EventHandler[];
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* @public
|
|
408
|
+
*/
|
|
409
|
+
export declare type EventListenerMap = Record<string, ListeningType>;
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* @public
|
|
413
|
+
*/
|
|
414
|
+
export declare interface IEventEmitter {
|
|
415
|
+
_events?: Record<string, any>;
|
|
416
|
+
_listeners?: ListeningMap;
|
|
417
|
+
_listeningTo?: ListeningMap;
|
|
418
|
+
_listenId?: string;
|
|
419
|
+
on(name: string | EventCallbackMap, callback?: EventCallback | EventContext, context?: EventContext): this;
|
|
420
|
+
off(name?: string | EventCallbackMap | null, callback?: EventCallback | EventContext | null, context?: EventContext): this;
|
|
421
|
+
trigger(name: string, ...args: any[]): this;
|
|
422
|
+
stopListening(obj?: any, name?: string | EventCallbackMap, callback?: EventCallback): this;
|
|
423
|
+
once(name: string | EventCallbackMap, callback?: EventCallback | EventContext, context?: EventContext): this;
|
|
424
|
+
listenTo(obj: ObjectListenedTo, name: string | EventCallbackMap, callback?: EventCallback): this;
|
|
425
|
+
listenToOnce(obj: any, name: string | EventCallbackMap, callback?: EventCallback): this;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* @public
|
|
430
|
+
*/
|
|
431
|
+
export declare type ListeningMap = Record<string, ListeningType>;
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* @public
|
|
435
|
+
*/
|
|
436
|
+
export declare interface ListeningType {
|
|
437
|
+
_events?: EventCallbackMap;
|
|
438
|
+
cleanup(): void;
|
|
439
|
+
count: number;
|
|
440
|
+
id: string;
|
|
441
|
+
interop: boolean;
|
|
442
|
+
listener: IEventEmitter;
|
|
443
|
+
obj: any;
|
|
444
|
+
start(name: string | EventCallbackMap, callback: EventCallback, context: any, _listening: ListeningType): this;
|
|
445
|
+
stop(name: string | EventCallbackMap, callback: EventCallback): void;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* @public
|
|
450
|
+
*/
|
|
451
|
+
export declare interface LocalForageWithExtensions {
|
|
452
|
+
setItem(key: string, value: any): Promise<any>;
|
|
453
|
+
getItem(key: string): Promise<any>;
|
|
454
|
+
removeItem(key: string): Promise<void>;
|
|
455
|
+
clear(): Promise<void>;
|
|
456
|
+
length(): Promise<number>;
|
|
457
|
+
key(keyIndex: number): Promise<string>;
|
|
458
|
+
keys(): Promise<string[]>;
|
|
459
|
+
setItems?(items: Record<string, any>): Promise<void>;
|
|
460
|
+
getItems?(keys: string[]): Promise<Record<string, any>>;
|
|
461
|
+
debouncedSetItems?: {
|
|
462
|
+
(items: Record<string, any>): Promise<void>;
|
|
463
|
+
flush?: () => void;
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* @public
|
|
469
|
+
* **Models** are the basic data object in the framework --
|
|
470
|
+
* frequently representing a row in a table in a database on your server.
|
|
471
|
+
* A discrete chunk of data and a bunch of useful, related methods for
|
|
472
|
+
* performing computations and transformations on that data.
|
|
473
|
+
*/
|
|
474
|
+
export declare class Model<T extends ModelAttributes = ModelAttributes> extends EventEmitterObject {
|
|
475
|
+
_browserStorage?: Storage_2;
|
|
476
|
+
_changing: boolean;
|
|
477
|
+
_pending: boolean | ModelOptions;
|
|
478
|
+
_previousAttributes?: T;
|
|
479
|
+
_url: string;
|
|
480
|
+
_urlRoot: string;
|
|
481
|
+
attributes: T;
|
|
482
|
+
changed: Partial<T>;
|
|
483
|
+
cid: string;
|
|
484
|
+
collection?: Collection;
|
|
485
|
+
id: string | number;
|
|
486
|
+
validationError: string | number | null;
|
|
487
|
+
/**
|
|
488
|
+
* Create a new model with the specified attributes. A client id (`cid`)
|
|
489
|
+
* is automatically generated and assigned for you.
|
|
490
|
+
*/
|
|
491
|
+
constructor(attributes?: Partial<T>, options?: ModelOptions);
|
|
492
|
+
set browserStorage(storage: Storage_2);
|
|
493
|
+
get browserStorage(): Storage_2 | undefined;
|
|
494
|
+
/**
|
|
495
|
+
* The default name for the JSON `id` attribute is `"id"`. MongoDB and
|
|
496
|
+
* CouchDB users may want to set this to `"_id"` (by overriding this getter
|
|
497
|
+
* in a subclass).
|
|
498
|
+
*/
|
|
499
|
+
get idAttribute(): string;
|
|
500
|
+
/**
|
|
501
|
+
* The prefix is used to create the client id which is used to identify models locally.
|
|
502
|
+
* You may want to override this if you're experiencing name clashes with model ids.
|
|
503
|
+
*/
|
|
504
|
+
get cidPrefix(): string;
|
|
505
|
+
/**
|
|
506
|
+
* preinitialize is an empty function by default. You can override it with a function
|
|
507
|
+
* or object. preinitialize will run before any instantiation logic is run in the Model.
|
|
508
|
+
*/
|
|
509
|
+
preinitialize(...args: any[]): void;
|
|
510
|
+
/**
|
|
511
|
+
* Initialize is an empty function by default. Override it with your own
|
|
512
|
+
* initialization logic.
|
|
513
|
+
*/
|
|
514
|
+
initialize(attrs?: Partial<T>, options?: ModelOptions): void;
|
|
515
|
+
validate(attrs: Partial<T> | ObjectWithId, options?: ModelOptions): string | number | null | void;
|
|
516
|
+
/**
|
|
517
|
+
* Return a hash of defaults for the model's attributes.
|
|
518
|
+
*/
|
|
519
|
+
defaults(): Partial<T>;
|
|
520
|
+
/**
|
|
521
|
+
* Return a copy of the model's `attributes` object.
|
|
522
|
+
*/
|
|
523
|
+
toJSON(): T;
|
|
524
|
+
/**
|
|
525
|
+
* Override this if you need custom syncing semantics for *this* particular model.
|
|
526
|
+
*/
|
|
527
|
+
sync(method: SyncOperation, model: Model<any>, options: Options): any;
|
|
528
|
+
/**
|
|
529
|
+
* Get the value of an attribute.
|
|
530
|
+
*/
|
|
531
|
+
get<K extends keyof T>(attr: K): T[K];
|
|
532
|
+
keys(): string[];
|
|
533
|
+
values(): T[keyof T][];
|
|
534
|
+
pairs(): [keyof T, T[keyof T]][];
|
|
535
|
+
entries(): [keyof T, T[keyof T]][];
|
|
536
|
+
invert(): Record<string, keyof T>;
|
|
537
|
+
pick<K extends keyof T>(...args: K[]): Pick<T, K>;
|
|
538
|
+
omit<K extends keyof T>(...args: K[]): Omit<T, K>;
|
|
539
|
+
isEmpty(): boolean;
|
|
540
|
+
/**
|
|
541
|
+
* Returns `true` if the attribute contains a value that is not null
|
|
542
|
+
* or undefined.
|
|
543
|
+
*/
|
|
544
|
+
has(attr: keyof T): boolean;
|
|
545
|
+
/**
|
|
546
|
+
* Special-cased proxy to lodash's `matches` method.
|
|
547
|
+
*/
|
|
548
|
+
matches(attrs: Partial<T>): boolean;
|
|
549
|
+
/**
|
|
550
|
+
* Set a hash of model attributes on the object, firing `"change"`. This is
|
|
551
|
+
* the core primitive operation of a model, updating the data and notifying
|
|
552
|
+
* anyone who needs to know about the change in state. The heart of the beast.
|
|
553
|
+
*/
|
|
554
|
+
set(key: string | Partial<T> | ObjectWithId, val?: any, options?: ModelOptions): this;
|
|
555
|
+
/**
|
|
556
|
+
* Remove an attribute from the model, firing `"change"`. `unset` is a noop
|
|
557
|
+
* if the attribute doesn't exist.
|
|
558
|
+
*/
|
|
559
|
+
unset(attr: keyof T, options?: ModelOptions): this;
|
|
560
|
+
/**
|
|
561
|
+
* Clear all attributes on the model, firing `"change"`.
|
|
562
|
+
*/
|
|
563
|
+
clear(options?: ModelOptions): this;
|
|
564
|
+
/**
|
|
565
|
+
* Determine if the model has changed since the last `"change"` event.
|
|
566
|
+
* If you specify an attribute name, determine if that attribute has changed.
|
|
567
|
+
*/
|
|
568
|
+
hasChanged(attr?: keyof T): boolean;
|
|
569
|
+
/**
|
|
570
|
+
* Return an object containing all the attributes that have changed, or
|
|
571
|
+
* false if there are no changed attributes. Useful for determining what
|
|
572
|
+
* parts of a view need to be updated and/or what attributes need to be
|
|
573
|
+
* persisted to the server. Unset attributes will be set to undefined.
|
|
574
|
+
* You can also pass an attributes object to diff against the model,
|
|
575
|
+
* determining if there *would be* a change.
|
|
576
|
+
*/
|
|
577
|
+
changedAttributes(diff?: Partial<T>): Partial<T> | false;
|
|
578
|
+
/**
|
|
579
|
+
* Get the previous value of an attribute, recorded at the time the last
|
|
580
|
+
* `"change"` event was fired.
|
|
581
|
+
*/
|
|
582
|
+
previous<K extends keyof T>(attr: K): T[K] | null;
|
|
583
|
+
/**
|
|
584
|
+
* Get all of the attributes of the model at the time of the previous
|
|
585
|
+
* `"change"` event.
|
|
586
|
+
*/
|
|
587
|
+
previousAttributes(): T | undefined;
|
|
588
|
+
/**
|
|
589
|
+
* Fetch the model from the server, merging the response with the model's
|
|
590
|
+
* local attributes. Any changed attributes will trigger a "change" event.
|
|
591
|
+
*/
|
|
592
|
+
fetch(options?: Options): any;
|
|
593
|
+
/**
|
|
594
|
+
* Set a hash of model attributes, and sync the model to the server.
|
|
595
|
+
* If the server returns an attributes hash that differs, the model's
|
|
596
|
+
* state will be `set` again.
|
|
597
|
+
*/
|
|
598
|
+
save(key?: string | null | Partial<T>, val?: any, options?: ModelOptions): any;
|
|
599
|
+
/**
|
|
600
|
+
* Destroy this model on the server if it was already persisted.
|
|
601
|
+
* Optimistically removes the model from its collection, if it has one.
|
|
602
|
+
* If `wait: true` is passed, waits for the server to respond before removal.
|
|
603
|
+
*/
|
|
604
|
+
destroy(options?: ModelOptions): any;
|
|
605
|
+
get urlRoot(): string;
|
|
606
|
+
set urlRoot(root: string);
|
|
607
|
+
/**
|
|
608
|
+
* Default URL for the model's representation on the server -- if you're
|
|
609
|
+
* using Backbone's restful methods, override this to change the endpoint
|
|
610
|
+
* that will be called.
|
|
611
|
+
*/
|
|
612
|
+
get url(): string;
|
|
613
|
+
set url(url: string);
|
|
614
|
+
/**
|
|
615
|
+
* **parse** converts a response into the hash of attributes to be `set` on
|
|
616
|
+
* the model. The default implementation is just to pass the response along.
|
|
617
|
+
*/
|
|
618
|
+
parse(resp: any, options?: ModelOptions): Partial<T> | null | void;
|
|
619
|
+
/**
|
|
620
|
+
* A model is new if it has never been saved to the server, and lacks an id.
|
|
621
|
+
*/
|
|
622
|
+
isNew(): boolean;
|
|
623
|
+
/**
|
|
624
|
+
* Check if the model is currently in a valid state.
|
|
625
|
+
*/
|
|
626
|
+
isValid(options?: ModelOptions): boolean;
|
|
627
|
+
/**
|
|
628
|
+
* Run validation against the next complete set of model attributes,
|
|
629
|
+
* returning `true` if all is well. Otherwise, fire an `"invalid"` event.
|
|
630
|
+
*/
|
|
631
|
+
_validate(attrs: Partial<T> | ObjectWithId, options?: ModelOptions): boolean;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* @public
|
|
636
|
+
*/
|
|
637
|
+
export declare type ModelAttributes = Record<string | number, any> & {
|
|
638
|
+
id?: string | number;
|
|
639
|
+
};
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* @public
|
|
643
|
+
*/
|
|
644
|
+
export declare type ModelOptions = Options & {
|
|
645
|
+
collection?: Collection;
|
|
646
|
+
parse?: boolean;
|
|
647
|
+
unset?: boolean;
|
|
648
|
+
silent?: boolean;
|
|
649
|
+
validate?: boolean;
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* @public
|
|
654
|
+
*/
|
|
655
|
+
export declare function noConflict(): any;
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* @public
|
|
659
|
+
*/
|
|
660
|
+
export declare type ObjectListenedTo = object & {
|
|
661
|
+
_listenId?: string;
|
|
662
|
+
};
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* @public
|
|
666
|
+
*/
|
|
667
|
+
export declare type ObjectWithId = Record<string, any> & {
|
|
668
|
+
id: string | number;
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* @public
|
|
673
|
+
*/
|
|
674
|
+
export declare type Options = Record<string, any>;
|
|
675
|
+
|
|
676
|
+
/**
|
|
677
|
+
* @public
|
|
678
|
+
*/
|
|
679
|
+
declare const skeletor: SkeletorType;
|
|
680
|
+
export default skeletor;
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* @public
|
|
684
|
+
*/
|
|
685
|
+
export declare interface SkeletorType {
|
|
686
|
+
Collection: typeof Collection;
|
|
687
|
+
EventEmitter: typeof EventEmitter;
|
|
688
|
+
Model: typeof Model;
|
|
689
|
+
sync: typeof sync;
|
|
690
|
+
VERSION?: string;
|
|
691
|
+
noConflict?: () => SkeletorType;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
/**
|
|
695
|
+
* @public
|
|
696
|
+
*/
|
|
697
|
+
declare class Storage_2 {
|
|
698
|
+
storeInitialized: Promise<void>;
|
|
699
|
+
store: LocalForageWithExtensions;
|
|
700
|
+
name: string;
|
|
701
|
+
static sessionStorageInitialized: Promise<void>;
|
|
702
|
+
static localForage: typeof localForage;
|
|
703
|
+
constructor(id: string, type: 'local' | 'session' | 'indexed' | 'in_memory' | LocalForageWithExtensions, batchedWrites?: boolean);
|
|
704
|
+
/**
|
|
705
|
+
* @param type - The storage type: 'local', 'session', 'indexed', or 'in_memory'
|
|
706
|
+
* @param batchedWrites - Whether to enable batched writes
|
|
707
|
+
*/
|
|
708
|
+
initStore(type: 'local' | 'session' | 'indexed' | 'in_memory', batchedWrites: boolean): Promise<void>;
|
|
709
|
+
flush(): void;
|
|
710
|
+
clear(): Promise<void>;
|
|
711
|
+
sync(): {
|
|
712
|
+
(method: SyncOperation, model: Model, options: SyncOptions): Promise<void>;
|
|
713
|
+
__name__: string;
|
|
714
|
+
};
|
|
715
|
+
removeCollectionReference(model: Model, collection: Collection | undefined): Promise<any> | undefined;
|
|
716
|
+
addCollectionReference(model: Model, collection: Collection | undefined): Promise<any> | undefined;
|
|
717
|
+
getCollectionReferenceData(model: Model): Record<string, string[]>;
|
|
718
|
+
save(model: Model): Promise<any>;
|
|
719
|
+
create(model: Model, options: SyncOptions): Promise<any>;
|
|
720
|
+
update(model: Model): Promise<any>;
|
|
721
|
+
find(model: Model): Promise<any>;
|
|
722
|
+
findAll(): Promise<any[]>;
|
|
723
|
+
destroy(model: Model, collection: Collection | undefined): Promise<Model>;
|
|
724
|
+
getStorageSize(): Promise<number>;
|
|
725
|
+
getItemName(id: string | number): string;
|
|
726
|
+
}
|
|
727
|
+
export { Storage_2 as Storage }
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
* Override this function to change the manner in which Backbone persists
|
|
731
|
+
* models to the server. You will be passed the type of request, and the
|
|
732
|
+
* model in question. By default makes a `fetch()` API call
|
|
733
|
+
* to the model's `url()`.
|
|
734
|
+
*
|
|
735
|
+
* Some possible customizations could be:
|
|
736
|
+
*
|
|
737
|
+
* - Use `setTimeout` to batch rapid-fire updates into a single request.
|
|
738
|
+
* - Persist models via WebSockets instead of Ajax.
|
|
739
|
+
* - Persist models to browser storage
|
|
740
|
+
*/
|
|
741
|
+
/**
|
|
742
|
+
* @public
|
|
743
|
+
*/
|
|
744
|
+
export declare function sync(method: SyncOperation, model: Model | Collection<any>, options?: SyncOptions): Promise<any>;
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* @public
|
|
748
|
+
*/
|
|
749
|
+
export declare type SyncOperation = 'create' | 'update' | 'patch' | 'delete' | 'read';
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* @public
|
|
753
|
+
*/
|
|
754
|
+
export declare interface SyncOptions {
|
|
755
|
+
url?: string;
|
|
756
|
+
data?: any;
|
|
757
|
+
attrs?: any;
|
|
758
|
+
success?: (data?: any, options?: SyncOptions) => void;
|
|
759
|
+
error?: (error: any) => void;
|
|
760
|
+
xhr?: any;
|
|
761
|
+
wait?: boolean;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
export { }
|