@converse/skeletor 0.0.8 → 0.0.9

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.
Files changed (42) hide show
  1. package/README.md +38 -25
  2. package/dist/skeletor.js +9232 -5096
  3. package/dist/skeletor.js.map +1 -1
  4. package/dist/skeletor.min.js +74 -3
  5. package/dist/skeletor.min.js.map +1 -1
  6. package/package.json +21 -11
  7. package/src/collection.js +540 -395
  8. package/src/drivers/sessionStorage.js +222 -219
  9. package/src/element.js +132 -82
  10. package/src/eventemitter.js +187 -0
  11. package/src/helpers.js +143 -118
  12. package/src/{main.js → index.js} +21 -17
  13. package/src/listening.js +81 -0
  14. package/src/model.js +340 -238
  15. package/src/storage.js +222 -230
  16. package/src/types/collection.d.ts +366 -0
  17. package/src/types/collection.d.ts.map +1 -0
  18. package/src/types/drivers/sessionStorage.d.ts +37 -0
  19. package/src/types/drivers/sessionStorage.d.ts.map +1 -0
  20. package/src/types/element.d.ts +115 -0
  21. package/src/types/element.d.ts.map +1 -0
  22. package/src/types/eventemitter.d.ts +93 -0
  23. package/src/types/eventemitter.d.ts.map +1 -0
  24. package/src/types/helpers.d.ts +62 -0
  25. package/src/types/helpers.d.ts.map +1 -0
  26. package/src/types/index.d.ts +19 -0
  27. package/src/types/index.d.ts.map +1 -0
  28. package/src/types/listening.d.ts +40 -0
  29. package/src/types/listening.d.ts.map +1 -0
  30. package/src/types/model.d.ts +230 -0
  31. package/src/types/model.d.ts.map +1 -0
  32. package/src/types/storage.d.ts +35 -0
  33. package/src/types/storage.d.ts.map +1 -0
  34. package/src/types/utils/events.d.ts +28 -0
  35. package/src/types/utils/events.d.ts.map +1 -0
  36. package/src/utils/events.js +174 -0
  37. package/src/drivers/sessionStorage.js~ +0 -307
  38. package/src/events.js +0 -328
  39. package/src/history.js +0 -301
  40. package/src/overview.js +0 -191
  41. package/src/router.js +0 -119
  42. package/src/view.js +0 -267
@@ -0,0 +1,62 @@
1
+ export function guid(): string;
2
+ export function inherits(protoProps: any, staticProps: any): any;
3
+ export function getResolveablePromise(): Promise<any> & {
4
+ isResolved: boolean;
5
+ isPending: boolean;
6
+ isRejected: boolean;
7
+ resolve: Function;
8
+ reject: Function;
9
+ };
10
+ export function urlError(): void;
11
+ export function wrapError(model: any, options: any): void;
12
+ /**
13
+ * @typedef {import('./model.js').Model} Model
14
+ * @typedef {import('./collection.js').Collection} Collection
15
+ */
16
+ /**
17
+ * @param {Model | Collection} model
18
+ */
19
+ export function getSyncMethod(model: Model | Collection): any;
20
+ /**
21
+ * @typedef {Object} SyncOptions
22
+ * @property {string} [url]
23
+ * @property {any} [data]
24
+ * @property {any} [attrs]
25
+ * @property {Function} [success]
26
+ * @property {Function} [error]
27
+ * @property {any} [xhr]
28
+ */
29
+ /**
30
+ * Override this function to change the manner in which Backbone persists
31
+ * models to the server. You will be passed the type of request, and the
32
+ * model in question. By default makes a `fetch()` API call
33
+ * to the model's `url()`.
34
+ *
35
+ * Some possible customizations could be:
36
+ *
37
+ * - Use `setTimeout` to batch rapid-fire updates into a single request.
38
+ * - Persist models via WebSockets instead of Ajax.
39
+ * - Persist models to browser storage
40
+ *
41
+ * @param {'create'|'update'|'patch'} method
42
+ * @param {import('./model.js').Model} model
43
+ * @param {SyncOptions} [options]
44
+ */
45
+ export function sync(method: "create" | "update" | "patch", model: import("./model.js").Model, options?: SyncOptions): Promise<Response>;
46
+ /**
47
+ * Custom error for indicating timeouts
48
+ * @namespace _converse
49
+ */
50
+ export class NotImplementedError extends Error {
51
+ }
52
+ export type Model = import("./model.js").Model;
53
+ export type Collection = import("./collection.js").Collection;
54
+ export type SyncOptions = {
55
+ url?: string;
56
+ data?: any;
57
+ attrs?: any;
58
+ success?: Function;
59
+ error?: Function;
60
+ xhr?: any;
61
+ };
62
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../helpers.js"],"names":[],"mappings":"AAkBA,+BAGC;AASD,iEA6BC;AAED;gBAGgB,OAAO;eACP,OAAO;gBACP,OAAO;;;EAwCtB;AAGD,iCAEC;AAGD,0DAMC;AAWD;;;GAGG;AAGH;;GAEG;AACH,qCAFW,KAAK,GAAG,UAAU,OAK5B;AAED;;;;;;;;GAQG;AAEH;;;;;;;;;;;;;;;GAeG;AACH,6BAJW,QAAQ,GAAC,QAAQ,GAAC,OAAO,SACzB,OAAO,YAAY,EAAE,KAAK,YAC1B,WAAW,qBAsBrB;AAxLD;;;GAGG;AACH;CAAiD;oBAyHpC,OAAO,YAAY,EAAE,KAAK;yBAC1B,OAAO,iBAAiB,EAAE,UAAU;;UAcnC,MAAM;WACN,GAAG;YACH,GAAG;;;UAGH,GAAG"}
@@ -0,0 +1,19 @@
1
+ export default skeletor;
2
+ declare namespace skeletor {
3
+ let VERSION: string;
4
+ function noConflict(): {
5
+ Collection: typeof Collection;
6
+ ElementView: typeof ElementView;
7
+ EventEmitter: typeof EventEmitter;
8
+ Model: typeof Model;
9
+ sync: typeof sync;
10
+ };
11
+ }
12
+ import { Collection } from './collection.js';
13
+ import ElementView from './element.js';
14
+ import EventEmitter from './eventemitter.js';
15
+ import { Model } from './model.js';
16
+ import Storage from './storage.js';
17
+ import { sync } from './helpers.js';
18
+ export { Collection, ElementView, EventEmitter, Model, Storage, sync };
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.js"],"names":[],"mappings":";;;IA+BA;;;;;;MAGC;;2BA9B0B,iBAAiB;wBAHpB,cAAc;yBACb,mBAAmB;sBAGtB,YAAY;oBAFd,cAAc;qBAGb,cAAc"}
@@ -0,0 +1,40 @@
1
+ export default Listening;
2
+ /**
3
+ * A listening class that tracks and cleans up memory bindings
4
+ * when all callbacks have been offed.
5
+ */
6
+ declare class Listening {
7
+ /** @typedef {import('./eventemitter.js').default} EventEmitter */
8
+ /**
9
+ * @param {any} listener
10
+ * @param {any} obj
11
+ */
12
+ constructor(listener: any, obj: any);
13
+ id: any;
14
+ listener: any;
15
+ obj: any;
16
+ interop: boolean;
17
+ count: number;
18
+ _events: any;
19
+ /**
20
+ * @param {string} name
21
+ * @param {Function} callback
22
+ * @param {any} context
23
+ * @param {Listening} _listening
24
+ */
25
+ start(name: string, callback: Function, context: any, _listening: Listening): this;
26
+ /**
27
+ * Stop's listening to a callback (or several).
28
+ * Uses an optimized counter if the listenee uses Backbone.Events.
29
+ * Otherwise, falls back to manual tracking to support events
30
+ * library interop.
31
+ * @param {string} name
32
+ * @param {Function} callback
33
+ */
34
+ stop(name: string, callback: Function): void;
35
+ /**
36
+ * Cleans up memory bindings between the listener and the listenee.
37
+ */
38
+ cleanup(): void;
39
+ }
40
+ //# sourceMappingURL=listening.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listening.d.ts","sourceRoot":"","sources":["../listening.js"],"names":[],"mappings":";AAEA;;;GAGG;AACH;IAEE,kEAAkE;IAElE;;;OAGG;IACH,sBAHW,GAAG,OACH,GAAG,EASb;IANC,QAA4B;IAC5B,cAAwB;IACxB,SAAc;IACd,iBAAmB;IACnB,cAAc;IACd,aAAwB;IAG1B;;;;;OAKG;IACH,YALW,MAAM,+BAEN,GAAG,cACH,SAAS,QAmBnB;IAED;;;;;;;OAOG;IACH,WAHW,MAAM,4BAgBhB;IAED;;OAEG;IACH,gBAGC;CACF"}
@@ -0,0 +1,230 @@
1
+ export type Collection = import("./collection.js").Collection;
2
+ export type Attributes = Record<string, any>;
3
+ export type Options = Record<string, any>;
4
+ export type ModelOptions = Record<string, any>;
5
+ declare const Model_base: {
6
+ new (...args: any[]): {
7
+ on(name: string, callback: (event: any, model: Model, collection: import("./collection.js").Collection, options: Record<string, any>) => any, context: any): /*elided*/ any;
8
+ _events: any;
9
+ _listeners: {};
10
+ listenTo(obj: any, name: string, callback?: (event: any, model: Model, collection: import("./collection.js").Collection, options: Record<string, any>) => any): /*elided*/ any;
11
+ _listeningTo: {};
12
+ _listenId: any;
13
+ off(name: string, callback: (event: any, model: Model, collection: import("./collection.js").Collection, options: Record<string, any>) => any, context?: any): /*elided*/ any;
14
+ stopListening(obj?: any, name?: string, callback?: (event: any, model: Model, collection: import("./collection.js").Collection, options: Record<string, any>) => any): /*elided*/ any;
15
+ once(name: string, callback: (event: any, model: Model, collection: import("./collection.js").Collection, options: Record<string, any>) => any, context: any): /*elided*/ any;
16
+ listenToOnce(obj: any, name: string, callback?: (event: any, model: Model, collection: import("./collection.js").Collection, options: Record<string, any>) => any): /*elided*/ any;
17
+ trigger(name: string, ...args: any[]): /*elided*/ any;
18
+ };
19
+ } & ObjectConstructor;
20
+ /**
21
+ * @typedef {import('./collection.js').Collection} Collection
22
+ * @typedef {Record.<string, any>} Attributes
23
+ *
24
+ * @typedef {Record.<string, any>} Options
25
+ * @property {boolean} [validate]
26
+ *
27
+ * @typedef {Record.<string, any>} ModelOptions
28
+ * @property {Collection} [collection]
29
+ * @property {boolean} [parse]
30
+ * @property {boolean} [unset]
31
+ * @property {boolean} [silent]
32
+ */
33
+ /**
34
+ * **Models** are the basic data object in the framework --
35
+ * frequently representing a row in a table in a database on your server.
36
+ * A discrete chunk of data and a bunch of useful, related methods for
37
+ * performing computations and transformations on that data.
38
+ */
39
+ export class Model extends Model_base {
40
+ /**
41
+ * Create a new model with the specified attributes. A client id (`cid`)
42
+ * is automatically generated and assigned for you.
43
+ * @param {Attributes} [attributes]
44
+ * @param {ModelOptions} [options]
45
+ */
46
+ constructor(attributes?: Attributes, options?: ModelOptions, ...args: any[]);
47
+ cid: any;
48
+ attributes: {};
49
+ validationError: string;
50
+ collection: any;
51
+ changed: {};
52
+ /**
53
+ * @param {Storage} storage
54
+ */
55
+ set browserStorage(storage: Storage);
56
+ /**
57
+ * @returns {Storage} storage
58
+ */
59
+ get browserStorage(): Storage;
60
+ _browserStorage: Storage;
61
+ /**
62
+ * The default name for the JSON `id` attribute is `"id"`. MongoDB and
63
+ * CouchDB users may want to set this to `"_id"` (by overriding this getter
64
+ * in a subclass).
65
+ */
66
+ get idAttribute(): string;
67
+ /**
68
+ * The prefix is used to create the client id which is used to identify models locally.
69
+ * You may want to override this if you're experiencing name clashes with model ids.
70
+ */
71
+ get cidPrefix(): string;
72
+ /**
73
+ * preinitialize is an empty function by default. You can override it with a function
74
+ * or object. preinitialize will run before any instantiation logic is run in the Model.
75
+ */
76
+ preinitialize(): void;
77
+ /**
78
+ * Initialize is an empty function by default. Override it with your own
79
+ * initialization logic.
80
+ * @param {Attributes} [attrs]
81
+ * @param {ModelOptions} [options]
82
+ */
83
+ initialize(attrs?: Attributes, options?: ModelOptions): void;
84
+ /**
85
+ * @param {object} attrs
86
+ * @param {object} [options]
87
+ * @returns {string} The validation error message
88
+ */
89
+ validate(attrs: object, options?: object): string;
90
+ /**
91
+ * Return a copy of the model's `attributes` object.
92
+ */
93
+ toJSON(): any;
94
+ /**
95
+ * Override this if you need custom syncing semantics for *this* particular model.
96
+ * @param {'create'|'update'|'patch'|'delete'|'read'} method
97
+ * @param {Model} model
98
+ * @param {Options} options
99
+ */
100
+ sync(method: "create" | "update" | "patch" | "delete" | "read", model: Model, options: Options): any;
101
+ /**
102
+ * Get the value of an attribute.
103
+ * @param {string} attr
104
+ */
105
+ get(attr: string): any;
106
+ keys(): string[];
107
+ values(): any[];
108
+ pairs(): [string, any][];
109
+ entries(): [string, any][];
110
+ invert(): any;
111
+ pick(...args: any[]): any;
112
+ omit(...args: any[]): any;
113
+ isEmpty(): any;
114
+ /**
115
+ * Returns `true` if the attribute contains a value that is not null
116
+ * or undefined.
117
+ * @param {string} attr
118
+ */
119
+ has(attr: string): boolean;
120
+ /**
121
+ * Special-cased proxy to lodash's `matches` method.
122
+ * @param {Attributes} attrs
123
+ */
124
+ matches(attrs: Attributes): boolean;
125
+ /**
126
+ * Set a hash of model attributes on the object, firing `"change"`. This is
127
+ * the core primitive operation of a model, updating the data and notifying
128
+ * anyone who needs to know about the change in state. The heart of the beast.
129
+ * @param {string|Object} key
130
+ * @param {string|Object} [val]
131
+ * @param {Options} [options]
132
+ */
133
+ set(key: string | any, val?: string | any, options?: Options): false | this;
134
+ _changing: boolean;
135
+ _previousAttributes: any;
136
+ id: any;
137
+ _pending: boolean | Options;
138
+ /**
139
+ * Remove an attribute from the model, firing `"change"`. `unset` is a noop
140
+ * if the attribute doesn't exist.
141
+ * @param {string} attr
142
+ * @param {Options} [options]
143
+ */
144
+ unset(attr: string, options?: Options): false | this;
145
+ /**
146
+ * Clear all attributes on the model, firing `"change"`.
147
+ * @param {Options} options
148
+ */
149
+ clear(options: Options): false | this;
150
+ /**
151
+ * Determine if the model has changed since the last `"change"` event.
152
+ * If you specify an attribute name, determine if that attribute has changed.
153
+ * @param {string} [attr]
154
+ */
155
+ hasChanged(attr?: string): any;
156
+ /**
157
+ * Return an object containing all the attributes that have changed, or
158
+ * false if there are no changed attributes. Useful for determining what
159
+ * parts of a view need to be updated and/or what attributes need to be
160
+ * persisted to the server. Unset attributes will be set to undefined.
161
+ * You can also pass an attributes object to diff against the model,
162
+ * determining if there *would be* a change.
163
+ * @param {Object} diff
164
+ */
165
+ changedAttributes(diff: any): any;
166
+ /**
167
+ * Get the previous value of an attribute, recorded at the time the last
168
+ * `"change"` event was fired.
169
+ * @param {string} [attr]
170
+ */
171
+ previous(attr?: string): any;
172
+ /**
173
+ * Get all of the attributes of the model at the time of the previous
174
+ * `"change"` event.
175
+ */
176
+ previousAttributes(): any;
177
+ /**
178
+ * Fetch the model from the server, merging the response with the model's
179
+ * local attributes. Any changed attributes will trigger a "change" event.
180
+ * @param {Options} [options={}]
181
+ */
182
+ fetch(options?: Options): any;
183
+ /**
184
+ * Set a hash of model attributes, and sync the model to the server.
185
+ * If the server returns an attributes hash that differs, the model's
186
+ * state will be `set` again.
187
+ * @param {string|Attributes} [key]
188
+ * @param {boolean|number|string|Options} [val]
189
+ * @param {Options} [options]
190
+ */
191
+ save(key?: string | Attributes, val?: boolean | number | string | Options, options?: Options): any;
192
+ /**
193
+ * Destroy this model on the server if it was already persisted.
194
+ * Optimistically removes the model from its collection, if it has one.
195
+ * If `wait: true` is passed, waits for the server to respond before removal.
196
+ * @param {Options} [options]
197
+ */
198
+ destroy(options?: Options): boolean;
199
+ /**
200
+ * Default URL for the model's representation on the server -- if you're
201
+ * using Backbone's restful methods, override this to change the endpoint
202
+ * that will be called.
203
+ */
204
+ url(): any;
205
+ /**
206
+ * **parse** converts a response into the hash of attributes to be `set` on
207
+ * the model. The default implementation is just to pass the response along.
208
+ * @param {Options} resp
209
+ * @param {Options} [options]
210
+ */
211
+ parse(resp: Options, options?: Options): Options;
212
+ /**
213
+ * A model is new if it has never been saved to the server, and lacks an id.
214
+ */
215
+ isNew(): boolean;
216
+ /**
217
+ * Check if the model is currently in a valid state.
218
+ * @param {Options} [options]
219
+ */
220
+ isValid(options?: Options): boolean;
221
+ /**
222
+ * Run validation against the next complete set of model attributes,
223
+ * returning `true` if all is well. Otherwise, fire an `"invalid"` event.
224
+ * @param {Attributes} attrs
225
+ * @param {Options} [options]
226
+ */
227
+ _validate(attrs: Attributes, options?: Options): boolean;
228
+ }
229
+ export {};
230
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../model.js"],"names":[],"mappings":"yBAgBa,OAAO,iBAAiB,EAAE,UAAU;yBACpC,MAAM,CAAE,MAAM,EAAE,GAAG,CAAC;sBAEpB,MAAM,CAAE,MAAM,EAAE,GAAG,CAAC;2BAGpB,MAAM,CAAE,MAAM,EAAE,GAAG,CAAC;;;;;;;;;;;;;;;;AAPjC;;;;;;;;;;;;GAYG;AAEH;;;;;GAKG;AACH;IACE;;;;;OAKG;IACH,yBAHW,UAAU,YACV,YAAY,kBAyBtB;IAlBC,SAAmC;IACnC,eAAoB;IAGpB,wBAA2B;IAEH,gBAAoC;IAW5D,YAAiB;IAGnB;;OAEG;IACH,4BAFW,OAAO,EAIjB;IAED;;OAEG;IACH,sBAFa,OAAO,CAInB;IARC,yBAA8B;IAUhC;;;;OAIG;IAEH,0BAEC;IAED;;;OAGG;IAEH,wBAEC;IAED;;;OAGG;IAEH,sBAAkB;IAElB;;;;;OAKG;IACH,mBAHW,UAAU,YACV,YAAY,QAEM;IAE7B;;;;OAIG;IACH,gBAJW,MAAM,YACN,MAAM,GACJ,MAAM,CAIlB;IAED;;OAEG;IACH,cAEC;IAED;;;;;OAKG;IAEH,aALW,QAAQ,GAAC,QAAQ,GAAC,OAAO,GAAC,QAAQ,GAAC,MAAM,SACzC,KAAK,WACL,OAAO,OAKjB;IAED;;;OAGG;IACH,UAFW,MAAM,OAIhB;IAED,iBAEC;IAED,gBAEC;IAED,yBAEC;IAED,2BAEC;IAED,cAEC;IAED,0BAKC;IAED,0BAKC;IAED,eAEC;IAED;;;;OAIG;IACH,UAFW,MAAM,WAIhB;IAED;;;OAGG;IACH,eAFW,UAAU,WAIpB;IAED;;;;;;;OAOG;IACH,SAJW,MAAM,MAAO,QACb,MAAM,MAAO,YACb,OAAO,gBAuEjB;IA/CC,mBAAqB;IAGnB,yBAAiD;IAqBpB,QAAoC;IAI7C,4BAAuB;IAqB/C;;;;;OAKG;IACH,YAHW,MAAM,YACN,OAAO,gBAIjB;IAED;;;OAGG;IACH,eAFW,OAAO,gBAMjB;IAED;;;;OAIG;IACH,kBAFW,MAAM,OAKhB;IAED;;;;;;;;OAQG;IACH,kCAeC;IAED;;;;OAIG;IACH,gBAFW,MAAM,OAKhB;IAED;;;OAGG;IACH,0BAEC;IAED;;;;OAIG;IACH,gBAFW,OAAO,OAgBjB;IAED;;;;;;;OAOG;IACH,WAJW,MAAM,GAAC,UAAU,QACjB,OAAO,GAAC,MAAM,GAAC,MAAM,GAAC,OAAO,YAC7B,OAAO,OAiEjB;IAED;;;;;OAKG;IACH,kBAFW,OAAO,WA2BjB;IAED;;;;OAIG;IACH,WAKC;IAED;;;;;OAKG;IACH,YAHW,OAAO,YACP,OAAO,WAIjB;IAED;;OAEG;IACH,iBAEC;IAED;;;OAGG;IACH,kBAFW,OAAO,WAIjB;IAED;;;;;OAKG;IACH,iBAHW,UAAU,YACV,OAAO,WASjB;CACF"}
@@ -0,0 +1,35 @@
1
+ export default Storage;
2
+ declare class Storage {
3
+ constructor(id: any, type: any, batchedWrites?: boolean);
4
+ storeInitialized: Promise<void>;
5
+ store: any;
6
+ name: any;
7
+ /**
8
+ * @param {'local'|'session'|'indexed'|'in_memory'} type
9
+ * @param {boolean} batchedWrites
10
+ */
11
+ initStore(type: "local" | "session" | "indexed" | "in_memory", batchedWrites: boolean): Promise<void>;
12
+ flush(): any;
13
+ clear(): Promise<void>;
14
+ sync(): {
15
+ (method: any, model: any, options: any): Promise<void>;
16
+ __name__: string;
17
+ };
18
+ removeCollectionReference(model: any, collection: any): any;
19
+ addCollectionReference(model: any, collection: any): any;
20
+ getCollectionReferenceData(model: any): {};
21
+ save(model: any): Promise<any>;
22
+ create(model: any, options: any): Promise<any>;
23
+ update(model: any): Promise<any>;
24
+ find(model: any): any;
25
+ findAll(): Promise<any[]>;
26
+ destroy(model: any, collection: any): Promise<any>;
27
+ getStorageSize(): any;
28
+ getItemName(id: any): string;
29
+ }
30
+ declare namespace Storage {
31
+ export let sessionStorageInitialized: Promise<void>;
32
+ export { localForage };
33
+ }
34
+ import localForage from 'localforage';
35
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../storage.js"],"names":[],"mappings":";AAkBA;IACE,yDAgBC;IATG,gCAA2D;IAE3D,WAAiB;IAMnB,UAAc;IAGhB;;;OAGG;IACH,gBAHW,OAAO,GAAC,SAAS,GAAC,SAAS,GAAC,WAAW,iBACvC,OAAO,iBAgBjB;IAED,aAEC;IAED,uBAMC;IAED;;;MAiFC;IAED,4DAOC;IAED,yDAUC;IAED,2CAYC;IAED,+BAYC;IAED,+CASC;IAED,iCAEC;IAED,sBAEC;IAED,0BASC;IAED,mDAKC;IAED,sBAEC;IAED,6BAEC;CACF;;;;;wBA/OuB,aAAa"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Iterates over the standard `event, callback` (as well as the fancy multiple
3
+ * space-separated events `"change blur", callback` and jQuery-style event
4
+ * maps `{event: callback}`).
5
+ */
6
+ export function eventsApi(iteratee: any, events: any, name: any, callback: any, opts: any): any;
7
+ export function onApi(events: any, name: any, callback: any, options: any): any;
8
+ /**
9
+ * An try-catch guarded #on function, to prevent poisoning the global
10
+ * `_listening` variable.
11
+ * @param {any} obj
12
+ * @param {string} name
13
+ * @param {Function} callback
14
+ * @param {any} context
15
+ */
16
+ export function tryCatchOn(obj: any, name: string, callback: Function, context: any): any;
17
+ /**
18
+ * The reducing API that removes a callback from the `events` object.
19
+ */
20
+ export function offApi(events: any, name: any, callback: any, options: any): any;
21
+ /**
22
+ * Reduces the event callbacks into a map of `{event: onceWrapper}`.
23
+ * `offer` unbinds the `onceWrapper` after it has been called.
24
+ */
25
+ export function onceMap(map: any, name: any, callback: any, offer: any): any;
26
+ /** Handles triggering the appropriate event callbacks. */
27
+ export function triggerApi(objEvents: any, name: any, callback: any, args: any): any;
28
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../utils/events.js"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,gGAmBC;AAGD,gFAWC;AAED;;;;;;;GAOG;AACH,gCALW,GAAG,QACH,MAAM,+BAEN,GAAG,OAQb;AAED;;GAEG;AACH,iFAkDC;AAED;;;GAGG;AACH,6EASC;AAED,0DAA0D;AAC1D,qFASC"}
@@ -0,0 +1,174 @@
1
+ import once from 'lodash-es/once.js';
2
+ import keys from 'lodash-es/keys.js';
3
+
4
+ // Regular expression used to split event strings.
5
+ const eventSplitter = /\s+/;
6
+
7
+ /**
8
+ * Iterates over the standard `event, callback` (as well as the fancy multiple
9
+ * space-separated events `"change blur", callback` and jQuery-style event
10
+ * maps `{event: callback}`).
11
+ */
12
+ export function eventsApi(iteratee, events, name, callback, opts) {
13
+ let i = 0,
14
+ names;
15
+ if (name && typeof name === 'object') {
16
+ // Handle event maps.
17
+ if (callback !== undefined && 'context' in opts && opts.context === undefined) opts.context = callback;
18
+ for (names = keys(name); i < names.length; i++) {
19
+ events = eventsApi(iteratee, events, names[i], name[names[i]], opts);
20
+ }
21
+ } else if (name && eventSplitter.test(name)) {
22
+ // Handle space-separated event names by delegating them individually.
23
+ for (names = name.split(eventSplitter); i < names.length; i++) {
24
+ events = iteratee(events, names[i], callback, opts);
25
+ }
26
+ } else {
27
+ // Finally, standard events.
28
+ events = iteratee(events, name, callback, opts);
29
+ }
30
+ return events;
31
+ }
32
+
33
+ // The reducing API that adds a callback to the `events` object.
34
+ export function onApi(events, name, callback, options) {
35
+ if (callback) {
36
+ const handlers = events[name] || (events[name] = []);
37
+ const context = options.context,
38
+ ctx = options.ctx,
39
+ listening = options.listening;
40
+ if (listening) listening.count++;
41
+
42
+ handlers.push({ callback, context, ctx: context || ctx, listening });
43
+ }
44
+ return events;
45
+ }
46
+
47
+ /**
48
+ * An try-catch guarded #on function, to prevent poisoning the global
49
+ * `_listening` variable.
50
+ * @param {any} obj
51
+ * @param {string} name
52
+ * @param {Function} callback
53
+ * @param {any} context
54
+ */
55
+ export function tryCatchOn(obj, name, callback, context) {
56
+ try {
57
+ obj.on(name, callback, context);
58
+ } catch (e) {
59
+ return e;
60
+ }
61
+ }
62
+
63
+ /**
64
+ * The reducing API that removes a callback from the `events` object.
65
+ */
66
+ export function offApi(events, name, callback, options) {
67
+ if (!events) return;
68
+
69
+ const context = options.context,
70
+ listeners = options.listeners;
71
+ let i = 0,
72
+ names;
73
+
74
+ // Delete all event listeners and "drop" events.
75
+ if (!name && !context && !callback) {
76
+ for (names = keys(listeners); i < names.length; i++) {
77
+ listeners[names[i]].cleanup();
78
+ }
79
+ return;
80
+ }
81
+
82
+ names = name ? [name] : keys(events);
83
+ for (; i < names.length; i++) {
84
+ name = names[i];
85
+ const handlers = events[name];
86
+
87
+ // Bail out if there are no events stored.
88
+ if (!handlers) {
89
+ break;
90
+ }
91
+
92
+ // Find any remaining events.
93
+ const remaining = [];
94
+ for (let j = 0; j < handlers.length; j++) {
95
+ const handler = handlers[j];
96
+ if (
97
+ (callback && callback !== handler.callback && callback !== handler.callback._callback) ||
98
+ (context && context !== handler.context)
99
+ ) {
100
+ remaining.push(handler);
101
+ } else {
102
+ const listening = handler.listening;
103
+ if (listening) listening.stop(name, callback);
104
+ }
105
+ }
106
+
107
+ // Replace events if there are any remaining. Otherwise, clean up.
108
+ if (remaining.length) {
109
+ events[name] = remaining;
110
+ } else {
111
+ delete events[name];
112
+ }
113
+ }
114
+
115
+ return events;
116
+ }
117
+
118
+ /**
119
+ * Reduces the event callbacks into a map of `{event: onceWrapper}`.
120
+ * `offer` unbinds the `onceWrapper` after it has been called.
121
+ */
122
+ export function onceMap(map, name, callback, offer) {
123
+ if (callback) {
124
+ const _once = (map[name] = once(function () {
125
+ offer(name, _once);
126
+ callback.apply(this, arguments);
127
+ }));
128
+ _once._callback = callback;
129
+ }
130
+ return map;
131
+ }
132
+
133
+ /** Handles triggering the appropriate event callbacks. */
134
+ export function triggerApi(objEvents, name, callback, args) {
135
+ if (objEvents) {
136
+ const events = objEvents[name];
137
+ let allEvents = objEvents.all;
138
+ if (events && allEvents) allEvents = allEvents.slice();
139
+ if (events) triggerEvents(events, args);
140
+ if (allEvents) triggerEvents(allEvents, [name].concat(args));
141
+ }
142
+ return objEvents;
143
+ }
144
+
145
+ /**
146
+ * A difficult-to-believe, but optimized internal dispatch function for
147
+ * triggering events. Tries to keep the usual cases speedy (most internal
148
+ * Backbone events have 3 arguments).
149
+ */
150
+ function triggerEvents(events, args) {
151
+ let ev,
152
+ i = -1;
153
+ const l = events.length,
154
+ a1 = args[0],
155
+ a2 = args[1],
156
+ a3 = args[2];
157
+ switch (args.length) {
158
+ case 0:
159
+ while (++i < l) (ev = events[i]).callback.call(ev.ctx);
160
+ return;
161
+ case 1:
162
+ while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1);
163
+ return;
164
+ case 2:
165
+ while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1, a2);
166
+ return;
167
+ case 3:
168
+ while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1, a2, a3);
169
+ return;
170
+ default:
171
+ while (++i < l) (ev = events[i]).callback.apply(ev.ctx, args);
172
+ return;
173
+ }
174
+ }