ende 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/component.json +1 -1
- data/lib/assets/javascripts/aura/extensions/devise.js.coffee +7 -4
- data/lib/assets/javascripts/aura/extensions/routes.js.coffee +16 -8
- data/lib/assets/javascripts/aura/extensions/widget/lifecycleable.js.coffee +10 -5
- data/lib/assets/javascripts/widgets/authenticator/main.js.coffee +4 -8
- data/lib/assets/javascripts/widgets/authenticator/presenter.js.coffee +4 -4
- data/lib/assets/javascripts/widgets/authenticator/states/default.html +1 -1
- data/lib/assets/javascripts/widgets/tray/main.js.coffee +26 -0
- data/lib/ende/version.rb +1 -1
- data/lib/tasks/component.thor +1 -1
- data/vendor/assets/javascripts/ende/build.js +10008 -8202
- data/vendor/components/KapIT-observe-utils/component.json +16 -0
- data/vendor/components/KapIT-observe-utils/lib/observe-utils.js +780 -0
- data/vendor/components/chaijs-assertion-error/component.json +18 -0
- data/vendor/components/chaijs-assertion-error/index.js +110 -0
- data/vendor/components/chaijs-chai/component.json +47 -0
- data/vendor/components/chaijs-chai/index.js +1 -0
- data/vendor/components/chaijs-chai/lib/chai/assertion.js +130 -0
- data/vendor/components/chaijs-chai/lib/chai/core/assertions.js +1270 -0
- data/vendor/components/chaijs-chai/lib/chai/interface/assert.js +1080 -0
- data/vendor/components/chaijs-chai/lib/chai/interface/expect.js +12 -0
- data/vendor/components/chaijs-chai/lib/chai/interface/should.js +76 -0
- data/vendor/components/chaijs-chai/lib/chai/utils/addChainableMethod.js +94 -0
- data/vendor/components/chaijs-chai/lib/chai/utils/addMethod.js +37 -0
- data/vendor/components/chaijs-chai/lib/chai/utils/addProperty.js +40 -0
- data/vendor/components/chaijs-chai/lib/chai/utils/flag.js +32 -0
- data/vendor/components/chaijs-chai/lib/chai/utils/getActual.js +19 -0
- data/vendor/components/chaijs-chai/lib/chai/utils/getEnumerableProperties.js +25 -0
- data/vendor/components/chaijs-chai/lib/chai/utils/getMessage.js +49 -0
- data/vendor/components/chaijs-chai/lib/chai/utils/getName.js +20 -0
- data/vendor/components/chaijs-chai/lib/chai/utils/getPathValue.js +102 -0
- data/vendor/components/chaijs-chai/lib/chai/utils/getProperties.js +35 -0
- data/vendor/components/chaijs-chai/lib/chai/utils/index.js +108 -0
- data/vendor/components/chaijs-chai/lib/chai/utils/inspect.js +320 -0
- data/vendor/components/chaijs-chai/lib/chai/utils/objDisplay.js +48 -0
- data/vendor/components/chaijs-chai/lib/chai/utils/overwriteMethod.js +51 -0
- data/vendor/components/chaijs-chai/lib/chai/utils/overwriteProperty.js +54 -0
- data/vendor/components/chaijs-chai/lib/chai/utils/test.js +26 -0
- data/vendor/components/chaijs-chai/lib/chai/utils/transferFlags.js +44 -0
- data/vendor/components/chaijs-chai/lib/chai/utils/type.js +45 -0
- data/vendor/components/chaijs-chai/lib/chai.js +80 -0
- data/vendor/components/chaijs-deep-eql/component.json +18 -0
- data/vendor/components/chaijs-deep-eql/lib/eql.js +257 -0
- data/vendor/components/chaijs-type-detect/component.json +16 -0
- data/vendor/components/chaijs-type-detect/lib/type.js +142 -0
- data/vendor/components/component-bind/component.json +14 -0
- data/vendor/components/component-bind/index.js +24 -0
- data/vendor/components/component-delegate/component.json +19 -0
- data/vendor/components/component-delegate/index.js +42 -0
- data/vendor/components/component-event/component.json +13 -0
- data/vendor/components/component-event/index.js +40 -0
- data/vendor/components/component-jquery/component.json +14 -0
- data/vendor/components/component-jquery/index.js +9601 -0
- data/vendor/components/component-link-delegate/component.json +23 -0
- data/vendor/components/component-link-delegate/index.js +60 -0
- data/vendor/components/component-matches-selector/component.json +20 -0
- data/vendor/components/component-matches-selector/index.js +45 -0
- data/vendor/components/component-query/component.json +21 -0
- data/vendor/components/component-query/index.js +21 -0
- data/vendor/components/component-type/component.json +18 -0
- data/vendor/components/component-type/index.js +32 -0
- data/vendor/components/component-url/component.json +17 -0
- data/vendor/components/component-url/index.js +63 -0
- data/vendor/components/components-modernizr/component.json +18 -0
- data/vendor/components/components-modernizr/modernizr.js +1393 -0
- data/vendor/components/discore-closest/component.json +14 -0
- data/vendor/components/discore-closest/index.js +18 -0
- data/vendor/components/indefinido-advisable/component.json +21 -0
- data/vendor/components/indefinido-advisable/index.js +1 -0
- data/vendor/components/indefinido-advisable/lib/advisable.js +60 -0
- data/vendor/components/indefinido-indemma/component.json +40 -0
- data/vendor/components/indefinido-indemma/index.js +1 -0
- data/vendor/components/indefinido-indemma/lib/extensions/rivets.js +23 -0
- data/vendor/components/indefinido-indemma/lib/record/associable.js +217 -0
- data/vendor/components/indefinido-indemma/lib/record/maid.js +24 -0
- data/vendor/components/indefinido-indemma/lib/record/resource.js +104 -0
- data/vendor/components/indefinido-indemma/lib/record/rest.js +36 -0
- data/vendor/components/indefinido-indemma/lib/record/restfulable.js +326 -0
- data/vendor/components/indefinido-indemma/lib/record/scopable.js +279 -0
- data/vendor/components/indefinido-indemma/lib/record/translationable.js +19 -0
- data/vendor/components/indefinido-indemma/lib/record/validatable.js +216 -0
- data/vendor/components/indefinido-indemma/lib/record/validations/associated.js +30 -0
- data/vendor/components/indefinido-indemma/lib/record/validations/confirmation.js +19 -0
- data/vendor/components/indefinido-indemma/lib/record/validations/cpf.js +60 -0
- data/vendor/components/indefinido-indemma/lib/record/validations/presence.js +19 -0
- data/vendor/components/indefinido-indemma/lib/record/validations/remote.js +71 -0
- data/vendor/components/indefinido-indemma/lib/record.js +167 -0
- data/vendor/components/indefinido-indemma/vendor/sinon.js +4290 -0
- data/vendor/components/indefinido-indemma/vendor/stampit.js +392 -0
- data/vendor/components/indefinido-observable/component.json +25 -0
- data/vendor/components/indefinido-observable/components/cjohansen-sinon/sinon.js +4290 -0
- data/vendor/components/indefinido-observable/index.js +1 -0
- data/vendor/components/indefinido-observable/lib/adapters/rivets.js +26 -0
- data/vendor/components/indefinido-observable/lib/observable.js +320 -0
- data/vendor/components/indefinido-observable/vendor/shims/accessors-legacy.js +92 -0
- data/vendor/components/indefinido-observable/vendor/shims/accessors.js +173 -0
- data/vendor/components/indefinido-observable/vendor/shims/array.indexOf.js +8 -0
- data/vendor/components/indefinido-observable/vendor/shims/object.create.js +77 -0
- data/vendor/components/mikeric-rivets/component.json +15 -0
- data/vendor/components/mikeric-rivets/dist/rivets.js +1239 -0
- data/vendor/components/paulmillr-es6-shim/component.json +17 -0
- data/vendor/components/paulmillr-es6-shim/es6-shim.js +985 -0
- data/vendor/components/pluma-assimilate/component.json +25 -0
- data/vendor/components/pluma-assimilate/dist/assimilate.js +87 -0
- data/vendor/components/segmentio-extend/component.json +13 -0
- data/vendor/components/segmentio-extend/index.js +15 -0
- metadata +98 -2
@@ -0,0 +1,780 @@
|
|
1
|
+
// Copyright 2012 Kap IT (http://www.kapit.fr/)
|
2
|
+
//
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the 'License');
|
4
|
+
// you may not use this file except in compliance with the License.
|
5
|
+
// You may obtain a copy of the License at
|
6
|
+
//
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
//
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
10
|
+
// distributed under the License is distributed on an 'AS IS' BASIS,
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
// See the License for the specific language governing permissions and
|
13
|
+
// limitations under the License.
|
14
|
+
// Author : François de Campredon (http://francois.de-campredon.fr/),
|
15
|
+
|
16
|
+
// ObjectUtils
|
17
|
+
// ===========
|
18
|
+
|
19
|
+
(function (global) {
|
20
|
+
'use strict';
|
21
|
+
|
22
|
+
/**
|
23
|
+
* @namespace
|
24
|
+
*/
|
25
|
+
var ObserveUtils;
|
26
|
+
if (typeof exports !== 'undefined') {
|
27
|
+
ObserveUtils = exports;
|
28
|
+
} else {
|
29
|
+
ObserveUtils = global.ObserveUtils = {};
|
30
|
+
}
|
31
|
+
|
32
|
+
// Utilities
|
33
|
+
// ---------
|
34
|
+
|
35
|
+
|
36
|
+
// borrowing some array methods
|
37
|
+
var slice = Function.call.bind(Array.prototype.slice),
|
38
|
+
map = Function.call.bind(Array.prototype.map);
|
39
|
+
|
40
|
+
// return true if the given property descriptor contains accessor
|
41
|
+
function isAccessorDescriptor(desc) {
|
42
|
+
if (typeof desc === 'undefined') {
|
43
|
+
return false;
|
44
|
+
}
|
45
|
+
return ('get' in desc || 'set' in desc);
|
46
|
+
}
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
// getPropertyDescriptor shim
|
51
|
+
// copied from [es6-shim](https://github.com/paulmillr/es6-shim)
|
52
|
+
function getPropertyDescriptor(target, name) {
|
53
|
+
var pd = Object.getOwnPropertyDescriptor(target, name),
|
54
|
+
proto = Object.getPrototypeOf(target);
|
55
|
+
while (typeof pd === 'undefined' && proto !== null) {
|
56
|
+
pd = Object.getOwnPropertyDescriptor(proto, name);
|
57
|
+
proto = Object.getPrototypeOf(proto);
|
58
|
+
}
|
59
|
+
return pd;
|
60
|
+
}
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
// egal shim
|
65
|
+
// copied from [the ecmascript wiki](http://wiki.ecmascript.org/doku.php?id=harmony:egal)
|
66
|
+
function sameValue(x, y) {
|
67
|
+
if (x === y) {
|
68
|
+
// 0 === -0, but they are not identical
|
69
|
+
return x !== 0 || 1 / x === 1 / y;
|
70
|
+
}
|
71
|
+
|
72
|
+
// NaN !== NaN, but they are identical.
|
73
|
+
// NaNs are the only non-reflexive value, i.e., if x !== x,
|
74
|
+
// then x is a NaN.
|
75
|
+
// isNaN is broken: it converts its argument to number, so
|
76
|
+
// isNaN('foo') => true
|
77
|
+
return x !== x && y !== y;
|
78
|
+
}
|
79
|
+
|
80
|
+
// cast a value as number, and test if the obtained result
|
81
|
+
// is a positive finite integer, throw an error otherwise
|
82
|
+
function isPositiveFiniteInteger(value, errorMessage) {
|
83
|
+
value = Number(value);
|
84
|
+
if (isNaN(value) || !isFinite(value) || value < 0 || value % 1 !== 0) {
|
85
|
+
throw new RangeError(errorMessage.replace('$', value));
|
86
|
+
}
|
87
|
+
return value;
|
88
|
+
}
|
89
|
+
|
90
|
+
// defineObservableProperties Implementation
|
91
|
+
// ------------------------------------------
|
92
|
+
|
93
|
+
// Uid generation helper
|
94
|
+
var uidCounter = 0;
|
95
|
+
|
96
|
+
// Define a property on an object that will call the Notifier.notify method when updated
|
97
|
+
function defineObservableProperty(target, property, originalValue) {
|
98
|
+
|
99
|
+
//we store the value in an non-enumerable property with generated unique name
|
100
|
+
var internalPropName = '_' + (uidCounter++) + property;
|
101
|
+
|
102
|
+
Object.defineProperty(target, internalPropName, {
|
103
|
+
value: originalValue,
|
104
|
+
writable: true,
|
105
|
+
enumerable: false,
|
106
|
+
configurable: true
|
107
|
+
});
|
108
|
+
|
109
|
+
//then we create accessor method for our 'hidden' property,
|
110
|
+
// that dispatch changesRecords when the value is updated
|
111
|
+
Object.defineProperty(target, property, {
|
112
|
+
get: function () {
|
113
|
+
return this[internalPropName];
|
114
|
+
},
|
115
|
+
set: function (value) {
|
116
|
+
if (!sameValue(value, this[internalPropName])) {
|
117
|
+
var oldValue = this[internalPropName];
|
118
|
+
Object.defineProperty(target, internalPropName, {
|
119
|
+
value: value,
|
120
|
+
writable: true,
|
121
|
+
enumerable: false,
|
122
|
+
configurable: true
|
123
|
+
});
|
124
|
+
var notifier = Object.getNotifier(this);
|
125
|
+
notifier.notify({ type: 'updated', name: property, oldValue: oldValue });
|
126
|
+
}
|
127
|
+
},
|
128
|
+
enumerable: true,
|
129
|
+
configurable: true
|
130
|
+
});
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
// call defineObservableProperty for each property name passed as 'rest argument'
|
135
|
+
|
136
|
+
/**
|
137
|
+
* Define observable properties on the given object an return it.
|
138
|
+
*
|
139
|
+
* @param {Object} target
|
140
|
+
* @param {...string} properties
|
141
|
+
* @returns {Object}
|
142
|
+
*/
|
143
|
+
ObserveUtils.defineObservableProperties = function (target, properties) {
|
144
|
+
if (Object(target) !== target) {
|
145
|
+
throw new TypeError('target must be an Object, given ' + target);
|
146
|
+
}
|
147
|
+
properties = slice(arguments, 1);
|
148
|
+
while (properties.length > 0) {
|
149
|
+
var property = properties.shift(),
|
150
|
+
descriptor = getPropertyDescriptor(target, property);
|
151
|
+
|
152
|
+
if (!descriptor || !isAccessorDescriptor(descriptor)) {
|
153
|
+
var originalValue = descriptor && descriptor.value;
|
154
|
+
defineObservableProperty(target, property, originalValue);
|
155
|
+
}
|
156
|
+
}
|
157
|
+
return target;
|
158
|
+
};
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
// List Implementation
|
163
|
+
// ------------------------------------------
|
164
|
+
|
165
|
+
/**
|
166
|
+
*
|
167
|
+
* @param length
|
168
|
+
* @returns {*}
|
169
|
+
* @constructor
|
170
|
+
* @function
|
171
|
+
*/
|
172
|
+
function List(length) {
|
173
|
+
if (arguments.length === 0) {
|
174
|
+
length = 0;
|
175
|
+
}
|
176
|
+
|
177
|
+
// in this case we create a list with a given length
|
178
|
+
if (arguments.length <= 1 && typeof length === 'number') {
|
179
|
+
if (this instanceof List) {
|
180
|
+
this.length = length;
|
181
|
+
}
|
182
|
+
else {
|
183
|
+
return new List(length);
|
184
|
+
}
|
185
|
+
}
|
186
|
+
else {
|
187
|
+
//here we create a list with initial values
|
188
|
+
if (!(this instanceof List)) {
|
189
|
+
return List.fromArray(slice(arguments));
|
190
|
+
}
|
191
|
+
else {
|
192
|
+
for (var i = 0, l = arguments.length ; i < l ; i++) {
|
193
|
+
this[i] = arguments[i];
|
194
|
+
}
|
195
|
+
this.length = arguments.length;
|
196
|
+
}
|
197
|
+
}
|
198
|
+
}
|
199
|
+
|
200
|
+
/**
|
201
|
+
* Observe a list
|
202
|
+
* @param {List} list
|
203
|
+
* @param {function} observer
|
204
|
+
*/
|
205
|
+
List.observe = function observe(list, observer) {
|
206
|
+
Object.observe(list, observer, ['new', 'updated', 'deleted', 'splice']);
|
207
|
+
};
|
208
|
+
|
209
|
+
|
210
|
+
/**
|
211
|
+
* Unobserve a list
|
212
|
+
* @param {List} list
|
213
|
+
* @param {function} observer
|
214
|
+
*/
|
215
|
+
List.unobserve = function unobserve(list, observer) {
|
216
|
+
Object.unobserve(list, observer);
|
217
|
+
};
|
218
|
+
|
219
|
+
/**
|
220
|
+
* Create a list from a given array
|
221
|
+
* @param array
|
222
|
+
* @returns {List}
|
223
|
+
*/
|
224
|
+
List.fromArray = function (array) {
|
225
|
+
if (!Array.isArray(array)) {
|
226
|
+
throw new Error();
|
227
|
+
}
|
228
|
+
|
229
|
+
var list = new List();
|
230
|
+
for (var i = 0, l = array.length ; i < l ; i++) {
|
231
|
+
list[i] = array[i];
|
232
|
+
}
|
233
|
+
list.length = array.length;
|
234
|
+
return list;
|
235
|
+
};
|
236
|
+
|
237
|
+
Object.defineProperties(List.prototype, {
|
238
|
+
/**
|
239
|
+
* hidden value holder for the length property
|
240
|
+
* @private
|
241
|
+
*/
|
242
|
+
'_length' : {
|
243
|
+
value : 0,
|
244
|
+
enumerable: false,
|
245
|
+
configurable: true,
|
246
|
+
writable: true
|
247
|
+
},
|
248
|
+
/**
|
249
|
+
* the length of the list
|
250
|
+
* @property {number} length
|
251
|
+
*/
|
252
|
+
'length' : {
|
253
|
+
get : function () {
|
254
|
+
return this._length;
|
255
|
+
},
|
256
|
+
set : function (value) {
|
257
|
+
value = isPositiveFiniteInteger(value, 'Invalid list length : $');
|
258
|
+
var notifier = Object.getNotifier(this),
|
259
|
+
oldValue = this._length,
|
260
|
+
removed = [],
|
261
|
+
self = this;
|
262
|
+
if (value !== oldValue) {
|
263
|
+
notifier.performChange('splice', function () {
|
264
|
+
Object.defineProperty(self, '_length', {
|
265
|
+
value : value,
|
266
|
+
enumerable: false,
|
267
|
+
configurable: true,
|
268
|
+
writable: true
|
269
|
+
});
|
270
|
+
|
271
|
+
if (oldValue > value) {
|
272
|
+
//delete values if the length have been decreased
|
273
|
+
for (var i = value; i < oldValue; i++) {
|
274
|
+
removed.push(self[i]);
|
275
|
+
self.delete(i);
|
276
|
+
}
|
277
|
+
}
|
278
|
+
|
279
|
+
notifier.notify({ type: 'updated', name: 'length', oldValue: oldValue });
|
280
|
+
});
|
281
|
+
}
|
282
|
+
if (oldValue > value) {
|
283
|
+
notifier.notify({
|
284
|
+
type: 'splice',
|
285
|
+
index : value,
|
286
|
+
removed : removed,
|
287
|
+
addedCount: 0
|
288
|
+
});
|
289
|
+
} else {
|
290
|
+
notifier.notify({
|
291
|
+
type: 'splice',
|
292
|
+
index : oldValue,
|
293
|
+
removed : removed,
|
294
|
+
addedCount: value - oldValue
|
295
|
+
});
|
296
|
+
}
|
297
|
+
|
298
|
+
},
|
299
|
+
enumerable: true,
|
300
|
+
configurable : true
|
301
|
+
}
|
302
|
+
});
|
303
|
+
|
304
|
+
/**
|
305
|
+
* Returns an Array copy of the list
|
306
|
+
* @returns {Array}
|
307
|
+
*/
|
308
|
+
List.prototype.toArray = function () {
|
309
|
+
return slice(this);
|
310
|
+
};
|
311
|
+
|
312
|
+
/**
|
313
|
+
* Returns an string representation of the list
|
314
|
+
* @returns {string}
|
315
|
+
*/
|
316
|
+
List.prototype.toString = function () {
|
317
|
+
return this.toArray().toString();
|
318
|
+
};
|
319
|
+
|
320
|
+
|
321
|
+
/**
|
322
|
+
* Returns an json representation of the list
|
323
|
+
* @returns {string}
|
324
|
+
*/
|
325
|
+
List.prototype.toJSON = function () {
|
326
|
+
return JSON.stringify(this.toArray());
|
327
|
+
};
|
328
|
+
|
329
|
+
/**
|
330
|
+
* set the givent value at the specified index.
|
331
|
+
* @param {number} index
|
332
|
+
* @param {*} value
|
333
|
+
* @return {*}
|
334
|
+
*/
|
335
|
+
List.prototype.set = function (index, value) {
|
336
|
+
index = isPositiveFiniteInteger(index, 'Invalid index : $');
|
337
|
+
|
338
|
+
var notifier = Object.getNotifier(this),
|
339
|
+
len = this.length,
|
340
|
+
self = this;
|
341
|
+
if (index >= len) {
|
342
|
+
notifier.performChange('splice', function () {
|
343
|
+
self[index] = value;
|
344
|
+
notifier.notify({ type: 'new', name: index});
|
345
|
+
Object.defineProperty(self, '_length', {
|
346
|
+
value : index + 1,
|
347
|
+
enumerable: false,
|
348
|
+
configurable: true,
|
349
|
+
writable: true
|
350
|
+
});
|
351
|
+
notifier.notify({ type: 'updated', name: 'length', oldValue: len });
|
352
|
+
});
|
353
|
+
|
354
|
+
notifier.notify({
|
355
|
+
type: 'splice',
|
356
|
+
index : len,
|
357
|
+
removed : [],
|
358
|
+
addedCount: this.length - len
|
359
|
+
});
|
360
|
+
}
|
361
|
+
else if (!sameValue(value, this[index])) {
|
362
|
+
var oldValue = this[index];
|
363
|
+
this[index] = value;
|
364
|
+
notifier.notify({ type: 'updated', name: index, oldValue: oldValue });
|
365
|
+
}
|
366
|
+
return value;
|
367
|
+
};
|
368
|
+
|
369
|
+
/**
|
370
|
+
* delete the value at the specified index.
|
371
|
+
* @param {number} index
|
372
|
+
* @return {boolean}
|
373
|
+
*/
|
374
|
+
List.prototype.delete = function (index) {
|
375
|
+
index = isPositiveFiniteInteger(index, 'Invalid index : $');
|
376
|
+
if (this.hasOwnProperty(index)) {
|
377
|
+
var oldValue = this[index];
|
378
|
+
if (delete this[index]) {
|
379
|
+
var notifier = Object.getNotifier(this);
|
380
|
+
notifier.notify({ type: 'deleted', name: index, oldValue: oldValue });
|
381
|
+
return true;
|
382
|
+
}
|
383
|
+
}
|
384
|
+
return false;
|
385
|
+
};
|
386
|
+
|
387
|
+
/**
|
388
|
+
* create a new list resulting of the concatenation of all the List and array
|
389
|
+
* passed as parameter with the addition of other values passed as parameter
|
390
|
+
* @param {...*} args
|
391
|
+
* @return {List}
|
392
|
+
*/
|
393
|
+
List.prototype.concat = function (args) {
|
394
|
+
args = map(arguments, function (item) {
|
395
|
+
return (item instanceof List) ? item.toArray() : item;
|
396
|
+
});
|
397
|
+
return List.fromArray(Array.prototype.concat.apply(this.toArray(), args));
|
398
|
+
};
|
399
|
+
|
400
|
+
/**
|
401
|
+
* Joins all elements of a List into a string.
|
402
|
+
* @param {string} [separator]
|
403
|
+
* @return {string}
|
404
|
+
*/
|
405
|
+
List.prototype.join = function (separator) {
|
406
|
+
return this.toArray().join(separator);
|
407
|
+
};
|
408
|
+
|
409
|
+
|
410
|
+
/**
|
411
|
+
* Removes the last element from a List and returns that element.
|
412
|
+
* @return {*}
|
413
|
+
*/
|
414
|
+
List.prototype.pop = function () {
|
415
|
+
if (Object(this) !== this) {
|
416
|
+
throw new TypeError('TODO');
|
417
|
+
}
|
418
|
+
var len = isPositiveFiniteInteger(this.length, 'TODO');
|
419
|
+
if (len === 0) {
|
420
|
+
return void(0);
|
421
|
+
} else {
|
422
|
+
var newLen = len - 1,
|
423
|
+
element = this[newLen],
|
424
|
+
notifier = Object.getNotifier(this),
|
425
|
+
self = this;
|
426
|
+
notifier.performChange('splice', function () {
|
427
|
+
delete self[newLen];
|
428
|
+
notifier.notify({ type: 'deleted', name: newLen, oldValue: element });
|
429
|
+
Object.defineProperty(self, '_length', {
|
430
|
+
value : newLen,
|
431
|
+
enumerable: false,
|
432
|
+
configurable: true,
|
433
|
+
writable: true
|
434
|
+
});
|
435
|
+
notifier.notify({ type: 'updated', name: 'length', oldValue: len });
|
436
|
+
});
|
437
|
+
|
438
|
+
notifier.notify({
|
439
|
+
type: 'splice',
|
440
|
+
index : newLen,
|
441
|
+
removed : [element],
|
442
|
+
addedCount: 0
|
443
|
+
});
|
444
|
+
|
445
|
+
return element;
|
446
|
+
}
|
447
|
+
};
|
448
|
+
|
449
|
+
/**
|
450
|
+
* Mutates a List by appending the given elements and returning the new length of the array.
|
451
|
+
* @param {...*} items
|
452
|
+
* @return {number}
|
453
|
+
*/
|
454
|
+
List.prototype.push = function () {
|
455
|
+
if (arguments.length > 0) {
|
456
|
+
var argumentsLength = arguments.length,
|
457
|
+
elements = arguments,
|
458
|
+
len = this.length,
|
459
|
+
notifier = Object.getNotifier(this),
|
460
|
+
self = this,
|
461
|
+
i, index;
|
462
|
+
notifier.performChange('splice', function () {
|
463
|
+
for (i = 0; i < argumentsLength; i++) {
|
464
|
+
index = len + i;
|
465
|
+
// avoid the usage of the set function and manually
|
466
|
+
// set the value and notify the changes to avoid the notification of
|
467
|
+
// multiple length modification
|
468
|
+
self[index] = elements[i];
|
469
|
+
notifier.notify({
|
470
|
+
type : 'new',
|
471
|
+
name : index
|
472
|
+
});
|
473
|
+
}
|
474
|
+
Object.defineProperty(self, '_length', {
|
475
|
+
value : len + argumentsLength,
|
476
|
+
enumerable: false,
|
477
|
+
configurable: true,
|
478
|
+
writable: true
|
479
|
+
});
|
480
|
+
notifier.notify({ type: 'updated', name: 'length', oldValue: len });
|
481
|
+
});
|
482
|
+
|
483
|
+
notifier.notify({
|
484
|
+
type: 'splice',
|
485
|
+
index : len,
|
486
|
+
removed : [],
|
487
|
+
addedCount: argumentsLength
|
488
|
+
});
|
489
|
+
}
|
490
|
+
return this.length;
|
491
|
+
};
|
492
|
+
|
493
|
+
/**
|
494
|
+
* Reverses a List in place. The first List element becomes the last and the last becomes the first.
|
495
|
+
* @return {List}
|
496
|
+
*/
|
497
|
+
List.prototype.reverse = function () {
|
498
|
+
var copy = this.toArray(),
|
499
|
+
arr = copy.slice().reverse(),
|
500
|
+
notifier = Object.getNotifier(this),
|
501
|
+
self = this;
|
502
|
+
|
503
|
+
notifier.performChange('splice', function () {
|
504
|
+
for (var i = 0, l = arr.length; i < l; i++) {
|
505
|
+
self.set(i, arr[i]);
|
506
|
+
}
|
507
|
+
});
|
508
|
+
|
509
|
+
notifier.notify({
|
510
|
+
type: 'splice',
|
511
|
+
index : 0,
|
512
|
+
removed : copy,
|
513
|
+
addedCount: this.length
|
514
|
+
});
|
515
|
+
|
516
|
+
return this;
|
517
|
+
};
|
518
|
+
|
519
|
+
/**
|
520
|
+
* Removes the first element from a List and returns that element. This method changes the length of the List.
|
521
|
+
* @return {*}
|
522
|
+
*/
|
523
|
+
List.prototype.shift = function () {
|
524
|
+
if (this.length === 0) {
|
525
|
+
return void(0);
|
526
|
+
}
|
527
|
+
var arr = this.toArray(),
|
528
|
+
element = arr.shift(),
|
529
|
+
notifier = Object.getNotifier(this),
|
530
|
+
self = this, len = this.length;
|
531
|
+
notifier.performChange('splice', function () {
|
532
|
+
for (var i = 0, l = arr.length; i < l; i++) {
|
533
|
+
self.set(i, arr[i]);
|
534
|
+
}
|
535
|
+
self.delete(len - 1);
|
536
|
+
|
537
|
+
Object.defineProperty(self, '_length', {
|
538
|
+
value : len - 1,
|
539
|
+
enumerable: false,
|
540
|
+
configurable: true,
|
541
|
+
writable: true
|
542
|
+
});
|
543
|
+
notifier.notify({ type: 'updated', name: 'length', oldValue: len });
|
544
|
+
});
|
545
|
+
|
546
|
+
notifier.notify({
|
547
|
+
type: 'splice',
|
548
|
+
index : 0,
|
549
|
+
removed : [element],
|
550
|
+
addedCount: 0
|
551
|
+
});
|
552
|
+
|
553
|
+
return element;
|
554
|
+
};
|
555
|
+
|
556
|
+
/**
|
557
|
+
* Returns a shallow copy of a portion of an List.
|
558
|
+
* @param {number} [start]
|
559
|
+
* @param {number} [end]
|
560
|
+
* @return {List}
|
561
|
+
*/
|
562
|
+
List.prototype.slice = function (start, end) {
|
563
|
+
return List.fromArray(this.toArray().slice(start, end));
|
564
|
+
};
|
565
|
+
|
566
|
+
/**
|
567
|
+
* Sorts the elements of a List in place and returns the List.
|
568
|
+
* @param {function} [compareFn]
|
569
|
+
* @return {List}
|
570
|
+
*/
|
571
|
+
List.prototype.sort = function (compareFn) {
|
572
|
+
var copy = this.toArray(),
|
573
|
+
arr = copy.slice().sort(compareFn),
|
574
|
+
notifier = Object.getNotifier(this),
|
575
|
+
self = this;
|
576
|
+
notifier.performChange('splice', function () {
|
577
|
+
for (var i = 0, l = arr.length; i < l; i++) {
|
578
|
+
self.set(i, arr[i]);
|
579
|
+
}
|
580
|
+
});
|
581
|
+
|
582
|
+
notifier.notify({
|
583
|
+
type: 'splice',
|
584
|
+
index : 0,
|
585
|
+
removed : copy,
|
586
|
+
addedCount: this.length
|
587
|
+
});
|
588
|
+
return this;
|
589
|
+
};
|
590
|
+
|
591
|
+
/**
|
592
|
+
* Changes the content of a List, adding new elements while removing old elements.
|
593
|
+
* @return {List}
|
594
|
+
*/
|
595
|
+
List.prototype.splice = function () {
|
596
|
+
var returnValue = [];
|
597
|
+
if (arguments.length > 0) {
|
598
|
+
var arr = this.toArray(),
|
599
|
+
notifier = Object.getNotifier(this),
|
600
|
+
len = this.length,
|
601
|
+
self = this,
|
602
|
+
i, l;
|
603
|
+
|
604
|
+
returnValue = Array.prototype.splice.apply(arr, arguments);
|
605
|
+
notifier.performChange('splice', function () {
|
606
|
+
for (i = 0, l = arr.length; i < l; i++) {
|
607
|
+
var oldValue = self[i];
|
608
|
+
if (!sameValue(oldValue, arr[i])) {
|
609
|
+
self[i] = arr[i];
|
610
|
+
notifier.notify(
|
611
|
+
i >= len ?
|
612
|
+
{type : 'new', name : i}:
|
613
|
+
{type : 'updated', name : i, oldValue : oldValue}
|
614
|
+
);
|
615
|
+
}
|
616
|
+
}
|
617
|
+
if (len !== arr.length) {
|
618
|
+
if (len > arr.length) {
|
619
|
+
//delete values if the length have been decreased
|
620
|
+
for (i = arr.length; i < len; i++) {
|
621
|
+
self.delete(i);
|
622
|
+
}
|
623
|
+
}
|
624
|
+
Object.defineProperty(self, '_length', {
|
625
|
+
value : arr.length,
|
626
|
+
enumerable: false,
|
627
|
+
configurable: true,
|
628
|
+
writable: true
|
629
|
+
});
|
630
|
+
notifier.notify({ type: 'updated', name: 'length', oldValue: len });
|
631
|
+
}
|
632
|
+
|
633
|
+
});
|
634
|
+
|
635
|
+
if (returnValue.length > 0 || arguments.length > 2) {
|
636
|
+
notifier.notify({
|
637
|
+
type: 'splice',
|
638
|
+
index : arguments[0],
|
639
|
+
removed : returnValue,
|
640
|
+
addedCount: arguments.length - 2
|
641
|
+
});
|
642
|
+
}
|
643
|
+
}
|
644
|
+
return List.fromArray(returnValue);
|
645
|
+
};
|
646
|
+
|
647
|
+
/**
|
648
|
+
* Adds one or more elements to the beginning of a List and returns the new length of the List.
|
649
|
+
* @return {number}
|
650
|
+
*/
|
651
|
+
List.prototype.unshift = function () {
|
652
|
+
if (arguments.length > 0) {
|
653
|
+
var arr = this.toArray(),
|
654
|
+
notifier = Object.getNotifier(this),
|
655
|
+
len = this.length,
|
656
|
+
self = this;
|
657
|
+
|
658
|
+
Array.prototype.unshift.apply(arr, arguments);
|
659
|
+
notifier.performChange('splice', function () {
|
660
|
+
for (var i = 0, l = arr.length; i < l; i++) {
|
661
|
+
var oldValue = self[i];
|
662
|
+
if (!sameValue(oldValue, arr[i])) {
|
663
|
+
// avoid the usage of the set function and manually
|
664
|
+
// set the value and notify the changes to avoid the notification of
|
665
|
+
// multiple length modification
|
666
|
+
self[i] = arr[i];
|
667
|
+
notifier.notify(
|
668
|
+
i >= len ?
|
669
|
+
{type : 'new', name : i}:
|
670
|
+
{type : 'updated', name : i, oldValue : oldValue}
|
671
|
+
);
|
672
|
+
}
|
673
|
+
}
|
674
|
+
|
675
|
+
if (len !== arr.length) {
|
676
|
+
if (len > arr.length) {
|
677
|
+
//delete values if the length have been decreased
|
678
|
+
for (i = arr.length; i < len; i++) {
|
679
|
+
self.delete(i);
|
680
|
+
}
|
681
|
+
}
|
682
|
+
Object.defineProperty(self, '_length', {
|
683
|
+
value : arr.length,
|
684
|
+
enumerable: false,
|
685
|
+
configurable: true,
|
686
|
+
writable: true
|
687
|
+
});
|
688
|
+
notifier.notify({ type: 'updated', name: 'length', oldValue: len });
|
689
|
+
}
|
690
|
+
});
|
691
|
+
|
692
|
+
notifier.notify({
|
693
|
+
type: 'splice',
|
694
|
+
index : 0,
|
695
|
+
removed : [],
|
696
|
+
addedCount: arguments.length
|
697
|
+
});
|
698
|
+
}
|
699
|
+
return this.length;
|
700
|
+
};
|
701
|
+
|
702
|
+
/**
|
703
|
+
* Apply a function against an accumulator and each value of the List (from left-to-right) as to reduce it to a single value.
|
704
|
+
* @param {function} callback
|
705
|
+
* @param {Object} [initialValue]
|
706
|
+
* @return {Object}
|
707
|
+
*/
|
708
|
+
List.prototype.reduce = Array.prototype.reduce;
|
709
|
+
|
710
|
+
/**
|
711
|
+
* Apply a function simultaneously against two values of the array (from right-to-left) as to reduce it to a single value.
|
712
|
+
* @param {function} callback
|
713
|
+
* @param {Object} [initialValue]
|
714
|
+
* @return {Object}
|
715
|
+
*/
|
716
|
+
List.prototype.reduceRight = Array.prototype.reduceRight;
|
717
|
+
|
718
|
+
/**
|
719
|
+
* Returns the first index at which a given element can be found in the List, or -1 if it is not present.
|
720
|
+
* @param {Object} searchElement
|
721
|
+
* @param {number} [fromIndex]
|
722
|
+
* @return {number}
|
723
|
+
*/
|
724
|
+
List.prototype.indexOf = Array.prototype.indexOf;
|
725
|
+
|
726
|
+
/**
|
727
|
+
* Returns the last index at which a given element can be found in the List, or -1 if it is not present. The List is searched backwards, starting at fromIndex.
|
728
|
+
* @param {Object} searchElement
|
729
|
+
* @param {number} [fromIndex]
|
730
|
+
* @return {number}
|
731
|
+
*/
|
732
|
+
List.prototype.lastIndexOf = Array.prototype.lastIndexOf;
|
733
|
+
|
734
|
+
/**
|
735
|
+
* Tests whether all elements in the List pass the test implemented by the provided function.
|
736
|
+
* @param {function} callback
|
737
|
+
* @param {Object} [thisObject]
|
738
|
+
* @return {boolean}
|
739
|
+
*/
|
740
|
+
List.prototype.every = Array.prototype.every;
|
741
|
+
|
742
|
+
/**
|
743
|
+
* Creates a new List with all elements that pass the test implemented by the provided function
|
744
|
+
* @param {function} callback
|
745
|
+
* @param {Object} [thisObject]
|
746
|
+
* @return {List}
|
747
|
+
*/
|
748
|
+
List.prototype.filter = function (callback, thisObject) {
|
749
|
+
return List.fromArray(this.toArray().filter(callback, thisObject));
|
750
|
+
};
|
751
|
+
|
752
|
+
/**
|
753
|
+
* Executes a provided function once per List element.
|
754
|
+
* @param {function} callback
|
755
|
+
* @param {Object} [thisObject]
|
756
|
+
* @return {void}
|
757
|
+
*/
|
758
|
+
List.prototype.forEach = Array.prototype.forEach;
|
759
|
+
|
760
|
+
/**
|
761
|
+
* Creates a new List with the results of calling a provided function on every element in this List.
|
762
|
+
* @param {function} callback
|
763
|
+
* @param {Object} [thisObject]
|
764
|
+
* @return {List}
|
765
|
+
*/
|
766
|
+
List.prototype.map = function (callback, thisObject) {
|
767
|
+
return List.fromArray(this.toArray().map(callback, thisObject));
|
768
|
+
};
|
769
|
+
|
770
|
+
/**
|
771
|
+
* Tests whether some element in the List passes the test implemented by the provided function.
|
772
|
+
* @param {function} callback
|
773
|
+
* @param {Object} [thisObject]
|
774
|
+
* @return {boolean}
|
775
|
+
*/
|
776
|
+
List.prototype.some = Array.prototype.some;
|
777
|
+
|
778
|
+
ObserveUtils.List = List;
|
779
|
+
|
780
|
+
})(this);
|