@converse/skeletor 0.0.5 → 0.0.6
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 +70 -7
- package/dist/skeletor.js +160 -160
- package/dist/skeletor.js.map +1 -1
- package/dist/skeletor.min.js +2 -2
- package/dist/skeletor.min.js.map +1 -1
- package/package.json +4 -3
- package/src/drivers/indexeddb-getitems.js~ +1116 -0
- package/src/drivers/indexeddb.js~ +1115 -0
- package/src/storage.js +11 -8
- package/src/storage.js~ +13 -9
- package/CHANGES.md +0 -37
- package/src/.events.js.swp +0 -0
- package/src/.helpers.js.swp +0 -0
- package/src/.history.js.swp +0 -0
- package/src/.model.js.swp +0 -0
- package/src/.overview.js.swp +0 -0
- package/src/.router.js.swp +0 -0
- package/src/.view.js.swp +0 -0
- package/src/collection.js~ +0 -737
- package/src/drivers/.sessionStorage.js.swp +0 -0
- package/src/drivers/sessionStorage.js~ +0 -316
- package/src/element-overview.js~ +0 -4
- package/src/element.js~ +0 -188
- package/src/events.js~ +0 -334
- package/src/helpers.js~ +0 -151
- package/src/history.js~ +0 -301
- package/src/htmlview.js~ +0 -14
- package/src/model.js~ +0 -439
- package/src/orderedlist.js~ +0 -88
- package/src/overview.js~ +0 -111
- package/src/router.js~ +0 -119
- package/src/vdomview.js~ +0 -15
- package/src/view.js~ +0 -267
package/dist/skeletor.js
CHANGED
|
@@ -1903,7 +1903,7 @@
|
|
|
1903
1903
|
throw new TypeError(FUNC_ERROR_TEXT);
|
|
1904
1904
|
}
|
|
1905
1905
|
|
|
1906
|
-
var memoized = function
|
|
1906
|
+
var memoized = function () {
|
|
1907
1907
|
var args = arguments,
|
|
1908
1908
|
key = resolver ? resolver.apply(this, args) : args[0],
|
|
1909
1909
|
cache = memoized.cache;
|
|
@@ -2232,7 +2232,7 @@
|
|
|
2232
2232
|
if (protoProps && has(protoProps, 'constructor')) {
|
|
2233
2233
|
child = protoProps.constructor;
|
|
2234
2234
|
} else {
|
|
2235
|
-
child = function
|
|
2235
|
+
child = function () {
|
|
2236
2236
|
return parent.apply(this, arguments);
|
|
2237
2237
|
};
|
|
2238
2238
|
} // Add static properties to the constructor function, if supplied.
|
|
@@ -2391,7 +2391,7 @@
|
|
|
2391
2391
|
var getTag = baseGetTag; // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
|
|
2392
2392
|
|
|
2393
2393
|
if (DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag$1 || Map && getTag(new Map()) != mapTag$1 || Promise$1 && getTag(Promise$1.resolve()) != promiseTag || Set && getTag(new Set()) != setTag$1 || WeakMap$1 && getTag(new WeakMap$1()) != weakMapTag$1) {
|
|
2394
|
-
getTag = function
|
|
2394
|
+
getTag = function (value) {
|
|
2395
2395
|
var result = baseGetTag(value),
|
|
2396
2396
|
Ctor = result == objectTag$1 ? value.constructor : undefined,
|
|
2397
2397
|
ctorString = Ctor ? toSource(Ctor) : '';
|
|
@@ -2766,7 +2766,7 @@
|
|
|
2766
2766
|
// maps `{event: callback}`).
|
|
2767
2767
|
|
|
2768
2768
|
|
|
2769
|
-
const eventsApi = function
|
|
2769
|
+
const eventsApi = function (iteratee, events, name, callback, opts) {
|
|
2770
2770
|
let i = 0,
|
|
2771
2771
|
names;
|
|
2772
2772
|
|
|
@@ -2835,7 +2835,7 @@
|
|
|
2835
2835
|
}; // The reducing API that adds a callback to the `events` object.
|
|
2836
2836
|
|
|
2837
2837
|
|
|
2838
|
-
const onApi = function
|
|
2838
|
+
const onApi = function (events, name, callback, options) {
|
|
2839
2839
|
if (callback) {
|
|
2840
2840
|
const handlers = events[name] || (events[name] = []);
|
|
2841
2841
|
const context = options.context,
|
|
@@ -2855,7 +2855,7 @@
|
|
|
2855
2855
|
// `_listening` variable.
|
|
2856
2856
|
|
|
2857
2857
|
|
|
2858
|
-
const tryCatchOn = function
|
|
2858
|
+
const tryCatchOn = function (obj, name, callback, context) {
|
|
2859
2859
|
try {
|
|
2860
2860
|
obj.on(name, callback, context);
|
|
2861
2861
|
} catch (e) {
|
|
@@ -2897,7 +2897,7 @@
|
|
|
2897
2897
|
}; // The reducing API that removes a callback from the `events` object.
|
|
2898
2898
|
|
|
2899
2899
|
|
|
2900
|
-
const offApi = function
|
|
2900
|
+
const offApi = function (events, name, callback, options) {
|
|
2901
2901
|
if (!events) return;
|
|
2902
2902
|
const context = options.context,
|
|
2903
2903
|
listeners = options.listeners;
|
|
@@ -2967,7 +2967,7 @@
|
|
|
2967
2967
|
// `offer` unbinds the `onceWrapper` after it has been called.
|
|
2968
2968
|
|
|
2969
2969
|
|
|
2970
|
-
const onceMap = function
|
|
2970
|
+
const onceMap = function (map, name, callback, offer) {
|
|
2971
2971
|
if (callback) {
|
|
2972
2972
|
const _once = map[name] = once(function () {
|
|
2973
2973
|
offer(name, _once);
|
|
@@ -2996,7 +2996,7 @@
|
|
|
2996
2996
|
}; // Handles triggering the appropriate event callbacks.
|
|
2997
2997
|
|
|
2998
2998
|
|
|
2999
|
-
const triggerApi = function
|
|
2999
|
+
const triggerApi = function (objEvents, name, callback, args) {
|
|
3000
3000
|
if (objEvents) {
|
|
3001
3001
|
const events = objEvents[name];
|
|
3002
3002
|
let allEvents = objEvents.all;
|
|
@@ -3011,7 +3011,7 @@
|
|
|
3011
3011
|
// Backbone events have 3 arguments).
|
|
3012
3012
|
|
|
3013
3013
|
|
|
3014
|
-
const triggerEvents = function
|
|
3014
|
+
const triggerEvents = function (events, args) {
|
|
3015
3015
|
let ev,
|
|
3016
3016
|
i = -1;
|
|
3017
3017
|
const l = events.length,
|
|
@@ -3049,7 +3049,7 @@
|
|
|
3049
3049
|
// when all callbacks have been offed.
|
|
3050
3050
|
|
|
3051
3051
|
|
|
3052
|
-
const Listening = function
|
|
3052
|
+
const Listening = function (listener, obj) {
|
|
3053
3053
|
this.id = listener._listenId;
|
|
3054
3054
|
this.listener = listener;
|
|
3055
3055
|
this.obj = obj;
|
|
@@ -5555,7 +5555,7 @@
|
|
|
5555
5555
|
});
|
|
5556
5556
|
|
|
5557
5557
|
// Backbone.js 1.4.0
|
|
5558
|
-
const Model = function
|
|
5558
|
+
const Model = function (attributes, options) {
|
|
5559
5559
|
let attrs = attributes || {};
|
|
5560
5560
|
options || (options = {});
|
|
5561
5561
|
this.preinitialize.apply(this, arguments);
|
|
@@ -5584,72 +5584,72 @@
|
|
|
5584
5584
|
cidPrefix: 'c',
|
|
5585
5585
|
// preinitialize is an empty function by default. You can override it with a function
|
|
5586
5586
|
// or object. preinitialize will run before any instantiation logic is run in the Model.
|
|
5587
|
-
preinitialize: function
|
|
5587
|
+
preinitialize: function () {},
|
|
5588
5588
|
// Initialize is an empty function by default. Override it with your own
|
|
5589
5589
|
// initialization logic.
|
|
5590
|
-
initialize: function
|
|
5590
|
+
initialize: function () {},
|
|
5591
5591
|
// Return a copy of the model's `attributes` object.
|
|
5592
|
-
toJSON: function
|
|
5592
|
+
toJSON: function (options) {
|
|
5593
5593
|
return clone(this.attributes);
|
|
5594
5594
|
},
|
|
5595
5595
|
// Proxy `Backbone.sync` by default -- but override this if you need
|
|
5596
5596
|
// custom syncing semantics for *this* particular model.
|
|
5597
|
-
sync: function
|
|
5597
|
+
sync: function (method, model, options) {
|
|
5598
5598
|
return getSyncMethod(this)(method, model, options);
|
|
5599
5599
|
},
|
|
5600
5600
|
// Get the value of an attribute.
|
|
5601
|
-
get: function
|
|
5601
|
+
get: function (attr) {
|
|
5602
5602
|
return this.attributes[attr];
|
|
5603
5603
|
},
|
|
5604
|
-
keys: function
|
|
5604
|
+
keys: function () {
|
|
5605
5605
|
return Object.keys(this.attributes);
|
|
5606
5606
|
},
|
|
5607
|
-
values: function
|
|
5607
|
+
values: function () {
|
|
5608
5608
|
return Object.values(this.attributes);
|
|
5609
5609
|
},
|
|
5610
|
-
pairs: function
|
|
5610
|
+
pairs: function () {
|
|
5611
5611
|
return this.entries();
|
|
5612
5612
|
},
|
|
5613
|
-
entries: function
|
|
5613
|
+
entries: function () {
|
|
5614
5614
|
return Object.entries(this.attributes);
|
|
5615
5615
|
},
|
|
5616
|
-
invert: function
|
|
5616
|
+
invert: function () {
|
|
5617
5617
|
return invert(this.attributes);
|
|
5618
5618
|
},
|
|
5619
|
-
pick: function
|
|
5619
|
+
pick: function (...args) {
|
|
5620
5620
|
if (args.length === 1 && Array.isArray(args[0])) {
|
|
5621
5621
|
args = args[0];
|
|
5622
5622
|
}
|
|
5623
5623
|
|
|
5624
5624
|
return pick(this.attributes, args);
|
|
5625
5625
|
},
|
|
5626
|
-
omit: function
|
|
5626
|
+
omit: function (...args) {
|
|
5627
5627
|
if (args.length === 1 && Array.isArray(args[0])) {
|
|
5628
5628
|
args = args[0];
|
|
5629
5629
|
}
|
|
5630
5630
|
|
|
5631
5631
|
return omit(this.attributes, args);
|
|
5632
5632
|
},
|
|
5633
|
-
isEmpty: function
|
|
5633
|
+
isEmpty: function () {
|
|
5634
5634
|
return isEmpty(this.attributes);
|
|
5635
5635
|
},
|
|
5636
5636
|
// Get the HTML-escaped value of an attribute.
|
|
5637
|
-
escape: function
|
|
5637
|
+
escape: function (attr) {
|
|
5638
5638
|
return escape(this.get(attr));
|
|
5639
5639
|
},
|
|
5640
5640
|
// Returns `true` if the attribute contains a value that is not null
|
|
5641
5641
|
// or undefined.
|
|
5642
|
-
has: function
|
|
5642
|
+
has: function (attr) {
|
|
5643
5643
|
return this.get(attr) != null;
|
|
5644
5644
|
},
|
|
5645
5645
|
// Special-cased proxy to lodash's `matches` method.
|
|
5646
|
-
matches: function
|
|
5646
|
+
matches: function (attrs) {
|
|
5647
5647
|
return !!iteratee(attrs)(this.attributes);
|
|
5648
5648
|
},
|
|
5649
5649
|
// Set a hash of model attributes on the object, firing `"change"`. This is
|
|
5650
5650
|
// the core primitive operation of a model, updating the data and notifying
|
|
5651
5651
|
// anyone who needs to know about the change in state. The heart of the beast.
|
|
5652
|
-
set: function
|
|
5652
|
+
set: function (key, val, options) {
|
|
5653
5653
|
if (key == null) return this; // Handle both `"key", value` and `{key: value}` -style arguments.
|
|
5654
5654
|
|
|
5655
5655
|
let attrs;
|
|
@@ -5722,13 +5722,13 @@
|
|
|
5722
5722
|
},
|
|
5723
5723
|
// Remove an attribute from the model, firing `"change"`. `unset` is a noop
|
|
5724
5724
|
// if the attribute doesn't exist.
|
|
5725
|
-
unset: function
|
|
5725
|
+
unset: function (attr, options) {
|
|
5726
5726
|
return this.set(attr, undefined, assignIn({}, options, {
|
|
5727
5727
|
unset: true
|
|
5728
5728
|
}));
|
|
5729
5729
|
},
|
|
5730
5730
|
// Clear all attributes on the model, firing `"change"`.
|
|
5731
|
-
clear: function
|
|
5731
|
+
clear: function (options) {
|
|
5732
5732
|
const attrs = {};
|
|
5733
5733
|
|
|
5734
5734
|
for (const key in this.attributes) attrs[key] = undefined;
|
|
@@ -5739,7 +5739,7 @@
|
|
|
5739
5739
|
},
|
|
5740
5740
|
// Determine if the model has changed since the last `"change"` event.
|
|
5741
5741
|
// If you specify an attribute name, determine if that attribute has changed.
|
|
5742
|
-
hasChanged: function
|
|
5742
|
+
hasChanged: function (attr) {
|
|
5743
5743
|
if (attr == null) return !isEmpty(this.changed);
|
|
5744
5744
|
return has(this.changed, attr);
|
|
5745
5745
|
},
|
|
@@ -5749,7 +5749,7 @@
|
|
|
5749
5749
|
// persisted to the server. Unset attributes will be set to undefined.
|
|
5750
5750
|
// You can also pass an attributes object to diff against the model,
|
|
5751
5751
|
// determining if there *would be* a change.
|
|
5752
|
-
changedAttributes: function
|
|
5752
|
+
changedAttributes: function (diff) {
|
|
5753
5753
|
if (!diff) return this.hasChanged() ? clone(this.changed) : false;
|
|
5754
5754
|
const old = this._changing ? this._previousAttributes : this.attributes;
|
|
5755
5755
|
const changed = {};
|
|
@@ -5766,18 +5766,18 @@
|
|
|
5766
5766
|
},
|
|
5767
5767
|
// Get the previous value of an attribute, recorded at the time the last
|
|
5768
5768
|
// `"change"` event was fired.
|
|
5769
|
-
previous: function
|
|
5769
|
+
previous: function (attr) {
|
|
5770
5770
|
if (attr == null || !this._previousAttributes) return null;
|
|
5771
5771
|
return this._previousAttributes[attr];
|
|
5772
5772
|
},
|
|
5773
5773
|
// Get all of the attributes of the model at the time of the previous
|
|
5774
5774
|
// `"change"` event.
|
|
5775
|
-
previousAttributes: function
|
|
5775
|
+
previousAttributes: function () {
|
|
5776
5776
|
return clone(this._previousAttributes);
|
|
5777
5777
|
},
|
|
5778
5778
|
// Fetch the model from the server, merging the response with the model's
|
|
5779
5779
|
// local attributes. Any changed attributes will trigger a "change" event.
|
|
5780
|
-
fetch: function
|
|
5780
|
+
fetch: function (options) {
|
|
5781
5781
|
options = assignIn({
|
|
5782
5782
|
parse: true
|
|
5783
5783
|
}, options);
|
|
@@ -5797,7 +5797,7 @@
|
|
|
5797
5797
|
// Set a hash of model attributes, and sync the model to the server.
|
|
5798
5798
|
// If the server returns an attributes hash that differs, the model's
|
|
5799
5799
|
// state will be `set` again.
|
|
5800
|
-
save: function
|
|
5800
|
+
save: function (key, val, options) {
|
|
5801
5801
|
// Handle both `"key", value` and `{key: value}` -style arguments.
|
|
5802
5802
|
let attrs;
|
|
5803
5803
|
|
|
@@ -5865,13 +5865,13 @@
|
|
|
5865
5865
|
// Destroy this model on the server if it was already persisted.
|
|
5866
5866
|
// Optimistically removes the model from its collection, if it has one.
|
|
5867
5867
|
// If `wait: true` is passed, waits for the server to respond before removal.
|
|
5868
|
-
destroy: function
|
|
5868
|
+
destroy: function (options) {
|
|
5869
5869
|
options = options ? clone(options) : {};
|
|
5870
5870
|
const model = this;
|
|
5871
5871
|
const success = options.success;
|
|
5872
5872
|
const wait = options.wait;
|
|
5873
5873
|
|
|
5874
|
-
const destroy = function
|
|
5874
|
+
const destroy = function () {
|
|
5875
5875
|
model.stopListening();
|
|
5876
5876
|
model.trigger('destroy', model, model.collection, options);
|
|
5877
5877
|
};
|
|
@@ -5897,7 +5897,7 @@
|
|
|
5897
5897
|
// Default URL for the model's representation on the server -- if you're
|
|
5898
5898
|
// using Backbone's restful methods, override this to change the endpoint
|
|
5899
5899
|
// that will be called.
|
|
5900
|
-
url: function
|
|
5900
|
+
url: function () {
|
|
5901
5901
|
const base = result(this, 'urlRoot') || result(this.collection, 'url') || urlError();
|
|
5902
5902
|
if (this.isNew()) return base;
|
|
5903
5903
|
const id = this.get(this.idAttribute);
|
|
@@ -5905,26 +5905,26 @@
|
|
|
5905
5905
|
},
|
|
5906
5906
|
// **parse** converts a response into the hash of attributes to be `set` on
|
|
5907
5907
|
// the model. The default implementation is just to pass the response along.
|
|
5908
|
-
parse: function
|
|
5908
|
+
parse: function (resp, options) {
|
|
5909
5909
|
return resp;
|
|
5910
5910
|
},
|
|
5911
5911
|
// Create a new model with identical attributes to this one.
|
|
5912
|
-
clone: function
|
|
5912
|
+
clone: function () {
|
|
5913
5913
|
return new this.constructor(this.attributes);
|
|
5914
5914
|
},
|
|
5915
5915
|
// A model is new if it has never been saved to the server, and lacks an id.
|
|
5916
|
-
isNew: function
|
|
5916
|
+
isNew: function () {
|
|
5917
5917
|
return !this.has(this.idAttribute);
|
|
5918
5918
|
},
|
|
5919
5919
|
// Check if the model is currently in a valid state.
|
|
5920
|
-
isValid: function
|
|
5920
|
+
isValid: function (options) {
|
|
5921
5921
|
return this._validate({}, assignIn({}, options, {
|
|
5922
5922
|
validate: true
|
|
5923
5923
|
}));
|
|
5924
5924
|
},
|
|
5925
5925
|
// Run validation against the next complete set of model attributes,
|
|
5926
5926
|
// returning `true` if all is well. Otherwise, fire an `"invalid"` event.
|
|
5927
|
-
_validate: function
|
|
5927
|
+
_validate: function (attrs, options) {
|
|
5928
5928
|
if (!options.validate || !this.validate) return true;
|
|
5929
5929
|
attrs = assignIn({}, this.attributes, attrs);
|
|
5930
5930
|
const error = this.validationError = this.validate(attrs, options) || null;
|
|
@@ -6984,11 +6984,11 @@
|
|
|
6984
6984
|
});
|
|
6985
6985
|
|
|
6986
6986
|
// Backbone.js 1.4.0
|
|
6987
|
-
const
|
|
6987
|
+
const slice = Array.prototype.slice; // Create a new **Collection**, perhaps to contain a specific type of `model`.
|
|
6988
6988
|
// If a `comparator` is specified, the Collection will maintain
|
|
6989
6989
|
// its models in sort order, as they're added and removed.
|
|
6990
6990
|
|
|
6991
|
-
const Collection = function
|
|
6991
|
+
const Collection = function (models, options) {
|
|
6992
6992
|
options || (options = {});
|
|
6993
6993
|
this.preinitialize.apply(this, arguments);
|
|
6994
6994
|
if (options.model) this.model = options.model;
|
|
@@ -7013,7 +7013,7 @@
|
|
|
7013
7013
|
remove: false
|
|
7014
7014
|
}; // Splices `insert` into `array` at index `at`.
|
|
7015
7015
|
|
|
7016
|
-
const splice$1 = function
|
|
7016
|
+
const splice$1 = function (array, insert, at) {
|
|
7017
7017
|
at = Math.min(Math.max(at, 0), array.length);
|
|
7018
7018
|
const tail = Array(array.length - at);
|
|
7019
7019
|
const length = insert.length;
|
|
@@ -7033,31 +7033,31 @@
|
|
|
7033
7033
|
model: Model,
|
|
7034
7034
|
// preinitialize is an empty function by default. You can override it with a function
|
|
7035
7035
|
// or object. preinitialize will run before any instantiation logic is run in the Collection.
|
|
7036
|
-
preinitialize: function
|
|
7036
|
+
preinitialize: function () {},
|
|
7037
7037
|
// Initialize is an empty function by default. Override it with your own
|
|
7038
7038
|
// initialization logic.
|
|
7039
|
-
initialize: function
|
|
7039
|
+
initialize: function () {},
|
|
7040
7040
|
// The JSON representation of a Collection is an array of the
|
|
7041
7041
|
// models' attributes.
|
|
7042
|
-
toJSON: function
|
|
7042
|
+
toJSON: function (options) {
|
|
7043
7043
|
return this.map(function (model) {
|
|
7044
7044
|
return model.toJSON(options);
|
|
7045
7045
|
});
|
|
7046
7046
|
},
|
|
7047
7047
|
// Proxy `Backbone.sync` by default.
|
|
7048
|
-
sync: function
|
|
7048
|
+
sync: function (method, model, options) {
|
|
7049
7049
|
return getSyncMethod(this)(method, model, options);
|
|
7050
7050
|
},
|
|
7051
7051
|
// Add a model, or list of models to the set. `models` may be Backbone
|
|
7052
7052
|
// Models or raw JavaScript objects to be converted to Models, or any
|
|
7053
7053
|
// combination of the two.
|
|
7054
|
-
add: function
|
|
7054
|
+
add: function (models, options) {
|
|
7055
7055
|
return this.set(models, assignIn({
|
|
7056
7056
|
merge: false
|
|
7057
7057
|
}, options, addOptions));
|
|
7058
7058
|
},
|
|
7059
7059
|
// Remove a model, or a list of models from the set.
|
|
7060
|
-
remove: function
|
|
7060
|
+
remove: function (models, options) {
|
|
7061
7061
|
options = assignIn({}, options);
|
|
7062
7062
|
const singular = !Array.isArray(models);
|
|
7063
7063
|
models = singular ? [models] : models.slice();
|
|
@@ -7079,7 +7079,7 @@
|
|
|
7079
7079
|
// removing models that are no longer present, and merging models that
|
|
7080
7080
|
// already exist in the collection, as necessary. Similar to **Model#set**,
|
|
7081
7081
|
// the core operation for updating the data contained by the collection.
|
|
7082
|
-
set: function
|
|
7082
|
+
set: function (models, options) {
|
|
7083
7083
|
if (models == null) return;
|
|
7084
7084
|
options = assignIn({}, setOptions, options);
|
|
7085
7085
|
|
|
@@ -7195,7 +7195,7 @@
|
|
|
7195
7195
|
|
|
7196
7196
|
return singular ? models[0] : models;
|
|
7197
7197
|
},
|
|
7198
|
-
clearStore: async function
|
|
7198
|
+
clearStore: async function (options = {}, filter = o => o) {
|
|
7199
7199
|
await Promise.all(this.models.filter(filter).map(m => {
|
|
7200
7200
|
return new Promise(resolve => {
|
|
7201
7201
|
m.destroy(Object.assign(options, {
|
|
@@ -7214,7 +7214,7 @@
|
|
|
7214
7214
|
// you can reset the entire set with a new list of models, without firing
|
|
7215
7215
|
// any granular `add` or `remove` events. Fires `reset` when finished.
|
|
7216
7216
|
// Useful for bulk operations and optimizations.
|
|
7217
|
-
reset: function
|
|
7217
|
+
reset: function (models, options) {
|
|
7218
7218
|
options = options ? clone(options) : {};
|
|
7219
7219
|
|
|
7220
7220
|
for (let i = 0; i < this.models.length; i++) {
|
|
@@ -7232,146 +7232,146 @@
|
|
|
7232
7232
|
return models;
|
|
7233
7233
|
},
|
|
7234
7234
|
// Add a model to the end of the collection.
|
|
7235
|
-
push: function
|
|
7235
|
+
push: function (model, options) {
|
|
7236
7236
|
return this.add(model, assignIn({
|
|
7237
7237
|
at: this.length
|
|
7238
7238
|
}, options));
|
|
7239
7239
|
},
|
|
7240
7240
|
// Remove a model from the end of the collection.
|
|
7241
|
-
pop: function
|
|
7241
|
+
pop: function (options) {
|
|
7242
7242
|
const model = this.at(this.length - 1);
|
|
7243
7243
|
return this.remove(model, options);
|
|
7244
7244
|
},
|
|
7245
7245
|
// Add a model to the beginning of the collection.
|
|
7246
|
-
unshift: function
|
|
7246
|
+
unshift: function (model, options) {
|
|
7247
7247
|
return this.add(model, assignIn({
|
|
7248
7248
|
at: 0
|
|
7249
7249
|
}, options));
|
|
7250
7250
|
},
|
|
7251
7251
|
// Remove a model from the beginning of the collection.
|
|
7252
|
-
shift: function
|
|
7252
|
+
shift: function (options) {
|
|
7253
7253
|
const model = this.at(0);
|
|
7254
7254
|
return this.remove(model, options);
|
|
7255
7255
|
},
|
|
7256
7256
|
// Slice out a sub-array of models from the collection.
|
|
7257
|
-
slice: function
|
|
7258
|
-
return
|
|
7257
|
+
slice: function () {
|
|
7258
|
+
return slice.apply(this.models, arguments);
|
|
7259
7259
|
},
|
|
7260
|
-
filter: function
|
|
7260
|
+
filter: function (callback, thisArg) {
|
|
7261
7261
|
return this.models.filter(isFunction(callback) ? callback : m => m.matches(callback), thisArg);
|
|
7262
7262
|
},
|
|
7263
|
-
every: function
|
|
7263
|
+
every: function (pred) {
|
|
7264
7264
|
return every(this.models.map(m => m.attributes), pred);
|
|
7265
7265
|
},
|
|
7266
|
-
difference: function
|
|
7266
|
+
difference: function (values) {
|
|
7267
7267
|
return difference(this.models, values);
|
|
7268
7268
|
},
|
|
7269
|
-
max: function
|
|
7269
|
+
max: function () {
|
|
7270
7270
|
return Math.max.apply(Math, this.models);
|
|
7271
7271
|
},
|
|
7272
|
-
min: function
|
|
7272
|
+
min: function () {
|
|
7273
7273
|
return Math.min.apply(Math, this.models);
|
|
7274
7274
|
},
|
|
7275
|
-
drop: function
|
|
7275
|
+
drop: function (n = 1) {
|
|
7276
7276
|
return this.models.slice(n);
|
|
7277
7277
|
},
|
|
7278
|
-
some: function
|
|
7278
|
+
some: function (pred) {
|
|
7279
7279
|
return some(this.models.map(m => m.attributes), pred);
|
|
7280
7280
|
},
|
|
7281
|
-
sortBy: function
|
|
7281
|
+
sortBy: function (iteratee) {
|
|
7282
7282
|
return sortBy(this.models, isFunction(iteratee) ? iteratee : m => isString(iteratee) ? m.get(iteratee) : m.matches(iteratee));
|
|
7283
7283
|
},
|
|
7284
|
-
isEmpty: function
|
|
7284
|
+
isEmpty: function () {
|
|
7285
7285
|
return isEmpty(this.models);
|
|
7286
7286
|
},
|
|
7287
|
-
keyBy: function
|
|
7287
|
+
keyBy: function (iteratee) {
|
|
7288
7288
|
return keyBy(this.models, iteratee);
|
|
7289
7289
|
},
|
|
7290
|
-
each: function
|
|
7290
|
+
each: function (callback, thisArg) {
|
|
7291
7291
|
return this.forEach(callback, thisArg);
|
|
7292
7292
|
},
|
|
7293
|
-
forEach: function
|
|
7293
|
+
forEach: function (callback, thisArg) {
|
|
7294
7294
|
return this.models.forEach(callback, thisArg);
|
|
7295
7295
|
},
|
|
7296
|
-
includes: function
|
|
7296
|
+
includes: function (item) {
|
|
7297
7297
|
return this.models.includes(item);
|
|
7298
7298
|
},
|
|
7299
|
-
size: function
|
|
7299
|
+
size: function () {
|
|
7300
7300
|
return this.models.length;
|
|
7301
7301
|
},
|
|
7302
|
-
countBy: function
|
|
7302
|
+
countBy: function (f) {
|
|
7303
7303
|
return countBy(this.models, isFunction(f) ? f : m => isString(f) ? m.get(f) : m.matches(f));
|
|
7304
7304
|
},
|
|
7305
|
-
groupBy: function
|
|
7305
|
+
groupBy: function (pred) {
|
|
7306
7306
|
return groupBy(this.models, isFunction(pred) ? pred : m => isString(pred) ? m.get(pred) : m.matches(pred));
|
|
7307
7307
|
},
|
|
7308
|
-
indexOf: function
|
|
7308
|
+
indexOf: function (fromIndex) {
|
|
7309
7309
|
return indexOf(this.models, fromIndex);
|
|
7310
7310
|
},
|
|
7311
|
-
findLastIndex: function
|
|
7311
|
+
findLastIndex: function (pred, fromIndex) {
|
|
7312
7312
|
return findLastIndex(this.models, isFunction(pred) ? pred : m => isString(pred) ? m.get(pred) : m.matches(pred), fromIndex);
|
|
7313
7313
|
},
|
|
7314
|
-
lastIndexOf: function
|
|
7314
|
+
lastIndexOf: function (fromIndex) {
|
|
7315
7315
|
return lastIndexOf(this.models, fromIndex);
|
|
7316
7316
|
},
|
|
7317
|
-
findIndex: function
|
|
7317
|
+
findIndex: function (pred) {
|
|
7318
7318
|
return findIndex(this.models, isFunction(pred) ? pred : m => isString(pred) ? m.get(pred) : m.matches(pred));
|
|
7319
7319
|
},
|
|
7320
|
-
last: function
|
|
7320
|
+
last: function () {
|
|
7321
7321
|
const length = this.models == null ? 0 : this.models.length;
|
|
7322
7322
|
return length ? this.models[length - 1] : undefined;
|
|
7323
7323
|
},
|
|
7324
|
-
head: function
|
|
7324
|
+
head: function () {
|
|
7325
7325
|
return this.models[0];
|
|
7326
7326
|
},
|
|
7327
|
-
first: function
|
|
7327
|
+
first: function () {
|
|
7328
7328
|
return this.head();
|
|
7329
7329
|
},
|
|
7330
|
-
map: function
|
|
7330
|
+
map: function (cb, thisArg) {
|
|
7331
7331
|
return this.models.map(isFunction(cb) ? cb : m => isString(cb) ? m.get(cb) : m.matches(cb), thisArg);
|
|
7332
7332
|
},
|
|
7333
|
-
reduce: function
|
|
7333
|
+
reduce: function (callback, initialValue) {
|
|
7334
7334
|
return this.models.reduce(callback, initialValue || this.models[0]);
|
|
7335
7335
|
},
|
|
7336
|
-
reduceRight: function
|
|
7336
|
+
reduceRight: function (callback, initialValue) {
|
|
7337
7337
|
return this.models.reduceRight(callback, initialValue || this.models[0]);
|
|
7338
7338
|
},
|
|
7339
|
-
toArray: function
|
|
7339
|
+
toArray: function () {
|
|
7340
7340
|
return Array.from(this.models);
|
|
7341
7341
|
},
|
|
7342
7342
|
// Get a model from the set by id, cid, model object with id or cid
|
|
7343
7343
|
// properties, or an attributes object that is transformed through modelId.
|
|
7344
|
-
get: function
|
|
7344
|
+
get: function (obj) {
|
|
7345
7345
|
if (obj == null) return undefined;
|
|
7346
7346
|
return this._byId[obj] || this._byId[this.modelId(this._isModel(obj) ? obj.attributes : obj)] || obj.cid && this._byId[obj.cid];
|
|
7347
7347
|
},
|
|
7348
7348
|
// Returns `true` if the model is in the collection.
|
|
7349
|
-
has: function
|
|
7349
|
+
has: function (obj) {
|
|
7350
7350
|
return this.get(obj) != null;
|
|
7351
7351
|
},
|
|
7352
7352
|
// Get the model at the given index.
|
|
7353
|
-
at: function
|
|
7353
|
+
at: function (index) {
|
|
7354
7354
|
if (index < 0) index += this.length;
|
|
7355
7355
|
return this.models[index];
|
|
7356
7356
|
},
|
|
7357
7357
|
// Return models with matching attributes. Useful for simple cases of
|
|
7358
7358
|
// `filter`.
|
|
7359
|
-
where: function
|
|
7359
|
+
where: function (attrs, first) {
|
|
7360
7360
|
return this[first ? 'find' : 'filter'](attrs);
|
|
7361
7361
|
},
|
|
7362
7362
|
// Return the first model with matching attributes. Useful for simple cases
|
|
7363
7363
|
// of `find`.
|
|
7364
|
-
findWhere: function
|
|
7364
|
+
findWhere: function (attrs) {
|
|
7365
7365
|
return this.where(attrs, true);
|
|
7366
7366
|
},
|
|
7367
|
-
find: function
|
|
7367
|
+
find: function (predicate, fromIndex) {
|
|
7368
7368
|
const pred = isFunction(predicate) ? predicate : m => m.matches(predicate);
|
|
7369
7369
|
return this.models.find(pred, fromIndex);
|
|
7370
7370
|
},
|
|
7371
7371
|
// Force the collection to re-sort itself. You don't need to call this under
|
|
7372
7372
|
// normal circumstances, as the set will maintain sort order as each item
|
|
7373
7373
|
// is added.
|
|
7374
|
-
sort: function
|
|
7374
|
+
sort: function (options) {
|
|
7375
7375
|
let comparator = this.comparator;
|
|
7376
7376
|
if (!comparator) throw new Error('Cannot sort a set without a comparator');
|
|
7377
7377
|
options || (options = {});
|
|
@@ -7388,13 +7388,13 @@
|
|
|
7388
7388
|
return this;
|
|
7389
7389
|
},
|
|
7390
7390
|
// Pluck an attribute from each model in the collection.
|
|
7391
|
-
pluck: function
|
|
7391
|
+
pluck: function (attr) {
|
|
7392
7392
|
return this.map(attr + '');
|
|
7393
7393
|
},
|
|
7394
7394
|
// Fetch the default set of models for this collection, resetting the
|
|
7395
7395
|
// collection when they arrive. If `reset: true` is passed, the response
|
|
7396
7396
|
// data will be passed through the `reset` method instead of `set`.
|
|
7397
|
-
fetch: function
|
|
7397
|
+
fetch: function (options) {
|
|
7398
7398
|
options = assignIn({
|
|
7399
7399
|
parse: true
|
|
7400
7400
|
}, options);
|
|
@@ -7416,7 +7416,7 @@
|
|
|
7416
7416
|
// Create a new instance of a model in this collection. Add the model to the
|
|
7417
7417
|
// collection immediately, unless `wait: true` is passed, in which case we
|
|
7418
7418
|
// wait for the server to agree.
|
|
7419
|
-
create: function
|
|
7419
|
+
create: function (model, options) {
|
|
7420
7420
|
options = options ? clone(options) : {};
|
|
7421
7421
|
const wait = options.wait;
|
|
7422
7422
|
const return_promise = options.promise;
|
|
@@ -7459,44 +7459,44 @@
|
|
|
7459
7459
|
},
|
|
7460
7460
|
// **parse** converts a response into a list of models to be added to the
|
|
7461
7461
|
// collection. The default implementation is just to pass it through.
|
|
7462
|
-
parse: function
|
|
7462
|
+
parse: function (resp, options) {
|
|
7463
7463
|
return resp;
|
|
7464
7464
|
},
|
|
7465
7465
|
// Create a new collection with an identical list of models as this one.
|
|
7466
|
-
clone: function
|
|
7466
|
+
clone: function () {
|
|
7467
7467
|
return new this.constructor(this.models, {
|
|
7468
7468
|
model: this.model,
|
|
7469
7469
|
comparator: this.comparator
|
|
7470
7470
|
});
|
|
7471
7471
|
},
|
|
7472
7472
|
// Define how to uniquely identify models in the collection.
|
|
7473
|
-
modelId: function
|
|
7473
|
+
modelId: function (attrs) {
|
|
7474
7474
|
var _this$model$prototype;
|
|
7475
7475
|
|
|
7476
7476
|
return attrs[((_this$model$prototype = this.model.prototype) === null || _this$model$prototype === void 0 ? void 0 : _this$model$prototype.idAttribute) || 'id'];
|
|
7477
7477
|
},
|
|
7478
7478
|
// Get an iterator of all models in this collection.
|
|
7479
|
-
values: function
|
|
7479
|
+
values: function () {
|
|
7480
7480
|
return new CollectionIterator(this, ITERATOR_VALUES);
|
|
7481
7481
|
},
|
|
7482
7482
|
// Get an iterator of all model IDs in this collection.
|
|
7483
|
-
keys: function
|
|
7483
|
+
keys: function () {
|
|
7484
7484
|
return new CollectionIterator(this, ITERATOR_KEYS);
|
|
7485
7485
|
},
|
|
7486
7486
|
// Get an iterator of all [ID, model] tuples in this collection.
|
|
7487
|
-
entries: function
|
|
7487
|
+
entries: function () {
|
|
7488
7488
|
return new CollectionIterator(this, ITERATOR_KEYSVALUES);
|
|
7489
7489
|
},
|
|
7490
7490
|
// Private method to reset all internal state. Called when the collection
|
|
7491
7491
|
// is first initialized or reset.
|
|
7492
|
-
_reset: function
|
|
7492
|
+
_reset: function () {
|
|
7493
7493
|
this.length = 0;
|
|
7494
7494
|
this.models = [];
|
|
7495
7495
|
this._byId = {};
|
|
7496
7496
|
},
|
|
7497
7497
|
// Prepare a hash of attributes (or other model) to be added to this
|
|
7498
7498
|
// collection.
|
|
7499
|
-
_prepareModel: function
|
|
7499
|
+
_prepareModel: function (attrs, options) {
|
|
7500
7500
|
if (this._isModel(attrs)) {
|
|
7501
7501
|
if (!attrs.collection) attrs.collection = this;
|
|
7502
7502
|
return attrs;
|
|
@@ -7510,7 +7510,7 @@
|
|
|
7510
7510
|
return false;
|
|
7511
7511
|
},
|
|
7512
7512
|
// Internal method called by both remove and set.
|
|
7513
|
-
_removeModels: function
|
|
7513
|
+
_removeModels: function (models, options) {
|
|
7514
7514
|
const removed = [];
|
|
7515
7515
|
|
|
7516
7516
|
for (let i = 0; i < models.length; i++) {
|
|
@@ -7539,18 +7539,18 @@
|
|
|
7539
7539
|
},
|
|
7540
7540
|
// Method for checking whether an object should be considered a model for
|
|
7541
7541
|
// the purposes of adding to the collection.
|
|
7542
|
-
_isModel: function
|
|
7542
|
+
_isModel: function (model) {
|
|
7543
7543
|
return model instanceof Model;
|
|
7544
7544
|
},
|
|
7545
7545
|
// Internal method to create a model's ties to a collection.
|
|
7546
|
-
_addReference: function
|
|
7546
|
+
_addReference: function (model, options) {
|
|
7547
7547
|
this._byId[model.cid] = model;
|
|
7548
7548
|
const id = this.modelId(model.attributes);
|
|
7549
7549
|
if (id != null) this._byId[id] = model;
|
|
7550
7550
|
model.on('all', this._onModelEvent, this);
|
|
7551
7551
|
},
|
|
7552
7552
|
// Internal method to sever a model's ties to a collection.
|
|
7553
|
-
_removeReference: function
|
|
7553
|
+
_removeReference: function (model, options) {
|
|
7554
7554
|
delete this._byId[model.cid];
|
|
7555
7555
|
const id = this.modelId(model.attributes);
|
|
7556
7556
|
if (id != null) delete this._byId[id];
|
|
@@ -7561,7 +7561,7 @@
|
|
|
7561
7561
|
// Sets need to update their indexes when models change ids. All other
|
|
7562
7562
|
// events simply proxy through. "add" and "remove" events that originate
|
|
7563
7563
|
// in other collections are ignored.
|
|
7564
|
-
_onModelEvent: function
|
|
7564
|
+
_onModelEvent: function (event, model, collection, options) {
|
|
7565
7565
|
if (model) {
|
|
7566
7566
|
if ((event === 'add' || event === 'remove') && collection !== this) return;
|
|
7567
7567
|
if (event === 'destroy') this.remove(model, options);
|
|
@@ -7596,7 +7596,7 @@
|
|
|
7596
7596
|
// which can operate on Iterables.
|
|
7597
7597
|
|
|
7598
7598
|
|
|
7599
|
-
const CollectionIterator = function
|
|
7599
|
+
const CollectionIterator = function (collection, kind) {
|
|
7600
7600
|
this._collection = collection;
|
|
7601
7601
|
this._kind = kind;
|
|
7602
7602
|
this._index = 0;
|
|
@@ -7663,7 +7663,7 @@
|
|
|
7663
7663
|
// and URL fragments. If the browser supports neither (old IE, natch),
|
|
7664
7664
|
// falls back to polling.
|
|
7665
7665
|
|
|
7666
|
-
const History = function
|
|
7666
|
+
const History = function () {
|
|
7667
7667
|
this.handlers = [];
|
|
7668
7668
|
this.checkUrl = this.checkUrl.bind(this); // Ensure that `History` can be used outside of the browser.
|
|
7669
7669
|
|
|
@@ -7688,12 +7688,12 @@
|
|
|
7688
7688
|
// twenty times a second.
|
|
7689
7689
|
interval: 50,
|
|
7690
7690
|
// Are we at the app root?
|
|
7691
|
-
atRoot: function
|
|
7691
|
+
atRoot: function () {
|
|
7692
7692
|
const path = this.location.pathname.replace(/[^\/]$/, '$&/');
|
|
7693
7693
|
return path === this.root && !this.getSearch();
|
|
7694
7694
|
},
|
|
7695
7695
|
// Does the pathname match the root?
|
|
7696
|
-
matchRoot: function
|
|
7696
|
+
matchRoot: function () {
|
|
7697
7697
|
const path = this.decodeFragment(this.location.pathname);
|
|
7698
7698
|
const rootPath = path.slice(0, this.root.length - 1) + '/';
|
|
7699
7699
|
return rootPath === this.root;
|
|
@@ -7701,28 +7701,28 @@
|
|
|
7701
7701
|
// Unicode characters in `location.pathname` are percent encoded so they're
|
|
7702
7702
|
// decoded for comparison. `%25` should not be decoded since it may be part
|
|
7703
7703
|
// of an encoded parameter.
|
|
7704
|
-
decodeFragment: function
|
|
7704
|
+
decodeFragment: function (fragment) {
|
|
7705
7705
|
return decodeURI(fragment.replace(/%25/g, '%2525'));
|
|
7706
7706
|
},
|
|
7707
7707
|
// In IE6, the hash fragment and search params are incorrect if the
|
|
7708
7708
|
// fragment contains `?`.
|
|
7709
|
-
getSearch: function
|
|
7709
|
+
getSearch: function () {
|
|
7710
7710
|
const match = this.location.href.replace(/#.*/, '').match(/\?.+/);
|
|
7711
7711
|
return match ? match[0] : '';
|
|
7712
7712
|
},
|
|
7713
7713
|
// Gets the true hash value. Cannot use location.hash directly due to bug
|
|
7714
7714
|
// in Firefox where location.hash will always be decoded.
|
|
7715
|
-
getHash: function
|
|
7715
|
+
getHash: function (window) {
|
|
7716
7716
|
const match = (window || this).location.href.match(/#(.*)$/);
|
|
7717
7717
|
return match ? match[1] : '';
|
|
7718
7718
|
},
|
|
7719
7719
|
// Get the pathname and search params, without the root.
|
|
7720
|
-
getPath: function
|
|
7720
|
+
getPath: function () {
|
|
7721
7721
|
const path = this.decodeFragment(this.location.pathname + this.getSearch()).slice(this.root.length - 1);
|
|
7722
7722
|
return path.charAt(0) === '/' ? path.slice(1) : path;
|
|
7723
7723
|
},
|
|
7724
7724
|
// Get the cross-browser normalized URL fragment from the path or hash.
|
|
7725
|
-
getFragment: function
|
|
7725
|
+
getFragment: function (fragment) {
|
|
7726
7726
|
if (fragment == null) {
|
|
7727
7727
|
if (this._usePushState || !this._wantsHashChange) {
|
|
7728
7728
|
fragment = this.getPath();
|
|
@@ -7735,7 +7735,7 @@
|
|
|
7735
7735
|
},
|
|
7736
7736
|
// Start the hash change handling, returning `true` if the current URL matches
|
|
7737
7737
|
// an existing route, and `false` otherwise.
|
|
7738
|
-
start: function
|
|
7738
|
+
start: function (options) {
|
|
7739
7739
|
if (History.started) throw new Error('history has already been started');
|
|
7740
7740
|
History.started = true; // Figure out the initial configuration. Do we need an iframe?
|
|
7741
7741
|
// Is pushState desired ... is it available?
|
|
@@ -7801,7 +7801,7 @@
|
|
|
7801
7801
|
},
|
|
7802
7802
|
// Disable history, perhaps temporarily. Not useful in a real app,
|
|
7803
7803
|
// but possibly useful for unit testing Routers.
|
|
7804
|
-
stop: function
|
|
7804
|
+
stop: function () {
|
|
7805
7805
|
// Remove window listeners.
|
|
7806
7806
|
if (this._usePushState) {
|
|
7807
7807
|
removeEventListener('popstate', this.checkUrl, false);
|
|
@@ -7821,15 +7821,15 @@
|
|
|
7821
7821
|
},
|
|
7822
7822
|
// Add a route to be tested when the fragment changes. Routes added later
|
|
7823
7823
|
// may override previous routes.
|
|
7824
|
-
route: function route
|
|
7824
|
+
route: function (route, callback) {
|
|
7825
7825
|
this.handlers.unshift({
|
|
7826
|
-
route:
|
|
7826
|
+
route: route,
|
|
7827
7827
|
callback: callback
|
|
7828
7828
|
});
|
|
7829
7829
|
},
|
|
7830
7830
|
// Checks the current URL to see if it has changed, and if it has,
|
|
7831
7831
|
// calls `loadUrl`, normalizing across the hidden iframe.
|
|
7832
|
-
checkUrl: function
|
|
7832
|
+
checkUrl: function (e) {
|
|
7833
7833
|
let current = this.getFragment(); // If the user pressed the back button, the iframe's hash will have
|
|
7834
7834
|
// changed and we should use that for comparison.
|
|
7835
7835
|
|
|
@@ -7844,7 +7844,7 @@
|
|
|
7844
7844
|
// Attempt to load the current URL fragment. If a route succeeds with a
|
|
7845
7845
|
// match, returns `true`. If no defined routes matches the fragment,
|
|
7846
7846
|
// returns `false`.
|
|
7847
|
-
loadUrl: function
|
|
7847
|
+
loadUrl: function (fragment) {
|
|
7848
7848
|
// If the root doesn't match, no routes can match either.
|
|
7849
7849
|
if (!this.matchRoot()) return false;
|
|
7850
7850
|
fragment = this.fragment = this.getFragment(fragment);
|
|
@@ -7862,7 +7862,7 @@
|
|
|
7862
7862
|
// The options object can contain `trigger: true` if you wish to have the
|
|
7863
7863
|
// route callback be fired (not usually desirable), or `replace: true`, if
|
|
7864
7864
|
// you wish to modify the current URL without adding an entry to the history.
|
|
7865
|
-
navigate: function
|
|
7865
|
+
navigate: function (fragment, options) {
|
|
7866
7866
|
if (!History.started) return false;
|
|
7867
7867
|
if (!options || options === true) options = {
|
|
7868
7868
|
trigger: !!options
|
|
@@ -7912,7 +7912,7 @@
|
|
|
7912
7912
|
},
|
|
7913
7913
|
// Update the hash location, either replacing the current entry, or adding
|
|
7914
7914
|
// a new one to the browser history.
|
|
7915
|
-
_updateHash: function
|
|
7915
|
+
_updateHash: function (location, fragment, replace) {
|
|
7916
7916
|
if (replace) {
|
|
7917
7917
|
const href = location.href.replace(/(javascript:|#).*$/, '');
|
|
7918
7918
|
location.replace(href + '#' + fragment);
|
|
@@ -7964,7 +7964,7 @@
|
|
|
7964
7964
|
// Backbone.js 1.4.0
|
|
7965
7965
|
// matched. Creating a new one sets its `routes` hash, if not set statically.
|
|
7966
7966
|
|
|
7967
|
-
const Router = function
|
|
7967
|
+
const Router = function (options = {}) {
|
|
7968
7968
|
this.history = options.history || new History();
|
|
7969
7969
|
this.preinitialize.apply(this, arguments);
|
|
7970
7970
|
if (options.routes) this.routes = options.routes;
|
|
@@ -7984,18 +7984,18 @@
|
|
|
7984
7984
|
Object.assign(Router.prototype, Events, {
|
|
7985
7985
|
// preinitialize is an empty function by default. You can override it with a function
|
|
7986
7986
|
// or object. preinitialize will run before any instantiation logic is run in the Router.
|
|
7987
|
-
preinitialize: function
|
|
7987
|
+
preinitialize: function () {},
|
|
7988
7988
|
// Initialize is an empty function by default. Override it with your own
|
|
7989
7989
|
// initialization logic.
|
|
7990
|
-
initialize: function
|
|
7990
|
+
initialize: function () {},
|
|
7991
7991
|
// Manually bind a single named route to a callback. For example:
|
|
7992
7992
|
//
|
|
7993
7993
|
// this.route('search/:query/p:num', 'search', function(query, num) {
|
|
7994
7994
|
// ...
|
|
7995
7995
|
// });
|
|
7996
7996
|
//
|
|
7997
|
-
route: function route
|
|
7998
|
-
if (!isRegExp(
|
|
7997
|
+
route: function (route, name, callback) {
|
|
7998
|
+
if (!isRegExp(route)) route = this._routeToRegExp(route);
|
|
7999
7999
|
|
|
8000
8000
|
if (isFunction(name)) {
|
|
8001
8001
|
callback = name;
|
|
@@ -8003,8 +8003,8 @@
|
|
|
8003
8003
|
}
|
|
8004
8004
|
|
|
8005
8005
|
if (!callback) callback = this[name];
|
|
8006
|
-
this.history.route(
|
|
8007
|
-
const args = this._extractParameters(
|
|
8006
|
+
this.history.route(route, fragment => {
|
|
8007
|
+
const args = this._extractParameters(route, fragment);
|
|
8008
8008
|
|
|
8009
8009
|
if (this.execute(callback, args, name) !== false) {
|
|
8010
8010
|
this.trigger.apply(this, ['route:' + name].concat(args));
|
|
@@ -8016,18 +8016,18 @@
|
|
|
8016
8016
|
},
|
|
8017
8017
|
// Execute a route handler with the provided parameters. This is an
|
|
8018
8018
|
// excellent place to do pre-route setup or post-route cleanup.
|
|
8019
|
-
execute: function
|
|
8019
|
+
execute: function (callback, args, name) {
|
|
8020
8020
|
if (callback) callback.apply(this, args);
|
|
8021
8021
|
},
|
|
8022
8022
|
// Simple proxy to `history` to save a fragment into the history.
|
|
8023
|
-
navigate: function
|
|
8023
|
+
navigate: function (fragment, options) {
|
|
8024
8024
|
this.history.navigate(fragment, options);
|
|
8025
8025
|
return this;
|
|
8026
8026
|
},
|
|
8027
8027
|
// Bind all defined routes to `history`. We have to reverse the
|
|
8028
8028
|
// order of the routes here to support behavior where the most general
|
|
8029
8029
|
// routes can be defined at the bottom of the route map.
|
|
8030
|
-
_bindRoutes: function
|
|
8030
|
+
_bindRoutes: function () {
|
|
8031
8031
|
if (!this.routes) return;
|
|
8032
8032
|
this.routes = result(this, 'routes');
|
|
8033
8033
|
let route;
|
|
@@ -8039,7 +8039,7 @@
|
|
|
8039
8039
|
},
|
|
8040
8040
|
// Convert a route string into a regular expression, suitable for matching
|
|
8041
8041
|
// against the current location hash.
|
|
8042
|
-
_routeToRegExp: function
|
|
8042
|
+
_routeToRegExp: function (route) {
|
|
8043
8043
|
route = route.replace(escapeRegExp, '\\$&').replace(optionalParam, '(?:$1)?').replace(namedParam, function (match, optional) {
|
|
8044
8044
|
return optional ? match : '([^/?]+)';
|
|
8045
8045
|
}).replace(splatParam, '([^?]*?)');
|
|
@@ -8048,7 +8048,7 @@
|
|
|
8048
8048
|
// Given a route, and a URL fragment that it matches, return the array of
|
|
8049
8049
|
// extracted decoded parameters. Empty or unmatched parameters will be
|
|
8050
8050
|
// treated as `null` to normalize cross-browser behavior.
|
|
8051
|
-
_extractParameters: function
|
|
8051
|
+
_extractParameters: function (route, fragment) {
|
|
8052
8052
|
const params = route.exec(fragment).slice(1);
|
|
8053
8053
|
return params.map(function (param, i) {
|
|
8054
8054
|
// Don't decode the search params.
|
|
@@ -8069,9 +8069,9 @@
|
|
|
8069
8069
|
l = o ? o.createPolicy("lit-html", {
|
|
8070
8070
|
createHTML: t => t
|
|
8071
8071
|
}) : void 0,
|
|
8072
|
-
n =
|
|
8072
|
+
n = `lit$${(Math.random() + "").slice(9)}$`,
|
|
8073
8073
|
h = "?" + n,
|
|
8074
|
-
r =
|
|
8074
|
+
r = `<${h}>`,
|
|
8075
8075
|
u = document,
|
|
8076
8076
|
c = (t = "") => u.createComment(t),
|
|
8077
8077
|
d = t => null === t || "object" != typeof t && "function" != typeof t,
|
|
@@ -8426,7 +8426,7 @@
|
|
|
8426
8426
|
// if an existing element is not provided...
|
|
8427
8427
|
|
|
8428
8428
|
|
|
8429
|
-
const View = function
|
|
8429
|
+
const View = function (options) {
|
|
8430
8430
|
this.cid = uniqueId('view');
|
|
8431
8431
|
this._domEvents = [];
|
|
8432
8432
|
this.preinitialize.apply(this, arguments);
|
|
@@ -8445,19 +8445,19 @@
|
|
|
8445
8445
|
Object.assign(View.prototype, Events, {
|
|
8446
8446
|
// The default `tagName` of a View's element is `"div"`.
|
|
8447
8447
|
tagName: 'div',
|
|
8448
|
-
$: function
|
|
8448
|
+
$: function (selector) {
|
|
8449
8449
|
return this.el.querySelectorAll(selector);
|
|
8450
8450
|
},
|
|
8451
8451
|
// preinitialize is an empty function by default. You can override it with a function
|
|
8452
8452
|
// or object. preinitialize will run before any instantiation logic is run in the View
|
|
8453
|
-
preinitialize: function
|
|
8453
|
+
preinitialize: function () {},
|
|
8454
8454
|
// Initialize is an empty function by default. Override it with your own
|
|
8455
8455
|
// initialization logic.
|
|
8456
|
-
initialize: function
|
|
8456
|
+
initialize: function () {},
|
|
8457
8457
|
// **render** is the core function that your view should override, in order
|
|
8458
8458
|
// to populate its element (`this.el`), with the appropriate HTML. The
|
|
8459
8459
|
// convention is for **render** to always return `this`.
|
|
8460
|
-
render: function
|
|
8460
|
+
render: function () {
|
|
8461
8461
|
isFunction(this.beforeRender) && this.beforeRender();
|
|
8462
8462
|
isFunction(this.toHTML) && V(this.toHTML(), this.el);
|
|
8463
8463
|
isFunction(this.afterRender) && this.afterRender();
|
|
@@ -8465,7 +8465,7 @@
|
|
|
8465
8465
|
},
|
|
8466
8466
|
// Remove this view by taking the element out of the DOM, and removing any
|
|
8467
8467
|
// applicable Backbone.Events listeners.
|
|
8468
|
-
remove: function
|
|
8468
|
+
remove: function () {
|
|
8469
8469
|
this._removeElement();
|
|
8470
8470
|
|
|
8471
8471
|
this.stopListening();
|
|
@@ -8474,13 +8474,13 @@
|
|
|
8474
8474
|
// Remove this view's element from the document and all event listeners
|
|
8475
8475
|
// attached to it. Exposed for subclasses using an alternative DOM
|
|
8476
8476
|
// manipulation API.
|
|
8477
|
-
_removeElement: function
|
|
8477
|
+
_removeElement: function () {
|
|
8478
8478
|
this.undelegateEvents();
|
|
8479
8479
|
if (this.el.parentNode) this.el.parentNode.removeChild(this.el);
|
|
8480
8480
|
},
|
|
8481
8481
|
// Change the view's element (`this.el` property) and re-delegate the
|
|
8482
8482
|
// view's events on the new element.
|
|
8483
|
-
setElement: function
|
|
8483
|
+
setElement: function (element) {
|
|
8484
8484
|
this.undelegateEvents();
|
|
8485
8485
|
|
|
8486
8486
|
this._setElement(element);
|
|
@@ -8491,7 +8491,7 @@
|
|
|
8491
8491
|
// Apply the `element` to the view. `element` can be a CSS selector,
|
|
8492
8492
|
// a string of HTML, or an Element node. If passed a NodeList or CSS
|
|
8493
8493
|
// selector, uses just the first match.
|
|
8494
|
-
_setElement: function
|
|
8494
|
+
_setElement: function (element) {
|
|
8495
8495
|
if (typeof element == 'string') {
|
|
8496
8496
|
if (paddedLt.test(element)) {
|
|
8497
8497
|
const el = document.createElement('div');
|
|
@@ -8519,7 +8519,7 @@
|
|
|
8519
8519
|
// pairs. Callbacks will be bound to the view, with `this` set properly.
|
|
8520
8520
|
// Uses event delegation for efficiency.
|
|
8521
8521
|
// Omitting the selector binds the event to `this.el`.
|
|
8522
|
-
delegateEvents: function
|
|
8522
|
+
delegateEvents: function (events) {
|
|
8523
8523
|
events || (events = result(this, 'events'));
|
|
8524
8524
|
if (!events) return this;
|
|
8525
8525
|
this.undelegateEvents();
|
|
@@ -8542,7 +8542,7 @@
|
|
|
8542
8542
|
// the event's `delegateTarget` property is set to it and the return the
|
|
8543
8543
|
// result of calling bound `listener` with the parameters given to the
|
|
8544
8544
|
// handler.
|
|
8545
|
-
delegate: function
|
|
8545
|
+
delegate: function (eventName, selector, listener) {
|
|
8546
8546
|
const root = this.el;
|
|
8547
8547
|
|
|
8548
8548
|
if (!root) {
|
|
@@ -8597,7 +8597,7 @@
|
|
|
8597
8597
|
// Clears all callbacks previously bound to the view by `delegateEvents`.
|
|
8598
8598
|
// You usually don't need to use this, but may wish to if you have multiple
|
|
8599
8599
|
// Backbone views attached to the same DOM element.
|
|
8600
|
-
undelegateEvents: function
|
|
8600
|
+
undelegateEvents: function () {
|
|
8601
8601
|
if (this.el) {
|
|
8602
8602
|
for (let i = 0, len = this._domEvents.length; i < len; i++) {
|
|
8603
8603
|
const item = this._domEvents[i];
|
|
@@ -8611,7 +8611,7 @@
|
|
|
8611
8611
|
},
|
|
8612
8612
|
// A finer-grained `undelegateEvents` for removing a single delegated event.
|
|
8613
8613
|
// `selector` and `listener` are both optional.
|
|
8614
|
-
undelegate: function
|
|
8614
|
+
undelegate: function (eventName, selector, listener) {
|
|
8615
8615
|
if (typeof selector === 'function') {
|
|
8616
8616
|
listener = selector;
|
|
8617
8617
|
selector = null;
|
|
@@ -8640,14 +8640,14 @@
|
|
|
8640
8640
|
},
|
|
8641
8641
|
// Produces a DOM element to be assigned to your view. Exposed for
|
|
8642
8642
|
// subclasses using an alternative DOM manipulation API.
|
|
8643
|
-
_createElement: function
|
|
8643
|
+
_createElement: function (tagName) {
|
|
8644
8644
|
return document.createElement(tagName);
|
|
8645
8645
|
},
|
|
8646
8646
|
// Ensure that the View has a DOM element to render into.
|
|
8647
8647
|
// If `this.el` is a string, pass it through `$()`, take the first
|
|
8648
8648
|
// matching element, and re-assign it to `el`. Otherwise, create
|
|
8649
8649
|
// an element from the `id`, `className` and `tagName` properties.
|
|
8650
|
-
_ensureElement: function
|
|
8650
|
+
_ensureElement: function () {
|
|
8651
8651
|
if (!this.el) {
|
|
8652
8652
|
const attrs = assignIn({}, result(this, 'attributes'));
|
|
8653
8653
|
if (this.id) attrs.id = result(this, 'id');
|
|
@@ -8661,7 +8661,7 @@
|
|
|
8661
8661
|
},
|
|
8662
8662
|
// Set attributes from a hash on this view's element. Exposed for
|
|
8663
8663
|
// subclasses using an alternative DOM manipulation API.
|
|
8664
|
-
_setAttributes: function
|
|
8664
|
+
_setAttributes: function (attrs) {
|
|
8665
8665
|
for (const attr in attrs) {
|
|
8666
8666
|
attr in this.el ? this.el[attr] = attrs[attr] : this.el.setAttribute(attr, attrs[attr]);
|
|
8667
8667
|
}
|