Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
47
gaia/distros/spark/apps/customizer/components/observe-utils/Gruntfile.js
Executable file
47
gaia/distros/spark/apps/customizer/components/observe-utils/Gruntfile.js
Executable file
|
|
@ -0,0 +1,47 @@
|
|||
// Copyright 2012 Kap IT (http://www.kapit.fr/)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the 'License');
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an 'AS IS' BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Author : François de Campredon (http://francois.de-campredon.fr/),
|
||||
|
||||
'use strict';
|
||||
module.exports = function (grunt) {
|
||||
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
|
||||
|
||||
grunt.initConfig({
|
||||
jshint: {
|
||||
options: {
|
||||
jshintrc: '.jshintrc'
|
||||
},
|
||||
all: [ 'lib/*.js', 'test/*.js', 'Gruntfile.js' ]
|
||||
},
|
||||
mocha : {
|
||||
index: ['test/index.html'],
|
||||
options: {
|
||||
run : true
|
||||
}
|
||||
},
|
||||
mochaTest : {
|
||||
test: {
|
||||
options: {
|
||||
reporter: 'spec'
|
||||
},
|
||||
src: ['test/node-index.js']
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
grunt.registerTask('test', ['jshint', 'mocha', 'mochaTest']);
|
||||
grunt.registerTask('default', ['test']);
|
||||
|
||||
|
||||
};
|
||||
176
gaia/distros/spark/apps/customizer/components/observe-utils/LICENSE
Executable file
176
gaia/distros/spark/apps/customizer/components/observe-utils/LICENSE
Executable file
|
|
@ -0,0 +1,176 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
12
gaia/distros/spark/apps/customizer/components/observe-utils/bower.json
Executable file
12
gaia/distros/spark/apps/customizer/components/observe-utils/bower.json
Executable file
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"name": "observe-utils",
|
||||
"version": "0.3.2",
|
||||
"main": "lib/observe-utils.js",
|
||||
"devDependencies": {
|
||||
"expect": "~0.2.0",
|
||||
"sinon": "http://sinonjs.org/releases/sinon-1.6.0.js",
|
||||
"observe-shim": "~0.4.0",
|
||||
"mocha": "~1.8.1",
|
||||
"es5-shim": "~2.0.8"
|
||||
}
|
||||
}
|
||||
14
gaia/distros/spark/apps/customizer/components/observe-utils/component.json
Executable file
14
gaia/distros/spark/apps/customizer/components/observe-utils/component.json
Executable file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"name": "observe-utils",
|
||||
"version": "0.3.2",
|
||||
"description": "An Object.observe harmony proposal shim",
|
||||
"main": "lib/observe-utils.js",
|
||||
"repo": "KapIT/observe-utils",
|
||||
"scripts": ["lib/observe-utils.js"],
|
||||
"keywords": [
|
||||
"observe",
|
||||
"observe-utils",
|
||||
"data binding"
|
||||
],
|
||||
"license": "Apache"
|
||||
}
|
||||
759
gaia/distros/spark/apps/customizer/components/observe-utils/lib/observe-utils.js
Executable file
759
gaia/distros/spark/apps/customizer/components/observe-utils/lib/observe-utils.js
Executable file
|
|
@ -0,0 +1,759 @@
|
|||
// Copyright 2012 Kap IT (http://www.kapit.fr/)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the 'License');
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an 'AS IS' BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Author : François de Campredon (http://francois.de-campredon.fr/),
|
||||
|
||||
// ObjectUtils
|
||||
// ===========
|
||||
|
||||
(function (global) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @namespace
|
||||
*/
|
||||
var ObserveUtils;
|
||||
if (typeof exports !== 'undefined') {
|
||||
ObserveUtils = exports;
|
||||
} else {
|
||||
ObserveUtils = global.ObserveUtils = {};
|
||||
}
|
||||
|
||||
// Utilities
|
||||
// ---------
|
||||
|
||||
|
||||
// borrowing some array methods
|
||||
var arrSlice = Function.call.bind(Array.prototype.slice),
|
||||
arrMap = Function.call.bind(Array.prototype.map);
|
||||
|
||||
// return true if the given property descriptor contains accessor
|
||||
function isAccessorDescriptor(desc) {
|
||||
if (typeof desc === 'undefined') {
|
||||
return false;
|
||||
}
|
||||
return ('get' in desc || 'set' in desc);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// getPropertyDescriptor shim
|
||||
// copied from [es6-shim](https://github.com/paulmillr/es6-shim)
|
||||
function getPropertyDescriptor(target, name) {
|
||||
var pd = Object.getOwnPropertyDescriptor(target, name),
|
||||
proto = Object.getPrototypeOf(target);
|
||||
while (typeof pd === 'undefined' && proto !== null) {
|
||||
pd = Object.getOwnPropertyDescriptor(proto, name);
|
||||
proto = Object.getPrototypeOf(proto);
|
||||
}
|
||||
return pd;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// egal shim
|
||||
// copied from [the ecmascript wiki](http://wiki.ecmascript.org/doku.php?id=harmony:egal)
|
||||
function sameValue(x, y) {
|
||||
if (x === y) {
|
||||
// 0 === -0, but they are not identical
|
||||
return x !== 0 || 1 / x === 1 / y;
|
||||
}
|
||||
|
||||
// NaN !== NaN, but they are identical.
|
||||
// NaNs are the only non-reflexive value, i.e., if x !== x,
|
||||
// then x is a NaN.
|
||||
// isNaN is broken: it converts its argument to number, so
|
||||
// isNaN('foo') => true
|
||||
return x !== x && y !== y;
|
||||
}
|
||||
|
||||
// cast a value as number, and test if the obtained result
|
||||
// is a positive finite integer, throw an error otherwise
|
||||
function isPositiveFiniteInteger(value, errorMessage) {
|
||||
value = Number(value);
|
||||
if (isNaN(value) || !isFinite(value) || value < 0 || value % 1 !== 0) {
|
||||
throw new RangeError(errorMessage.replace('$', value));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
// defineObservableProperties Implementation
|
||||
// ------------------------------------------
|
||||
|
||||
// Uid generation helper
|
||||
var uidCounter = 0;
|
||||
|
||||
// Define a property on an object that will call the Notifier.notify method when updated
|
||||
function defineObservableProperty(target, property, originalValue) {
|
||||
|
||||
//we store the value in an non-enumerable property with generated unique name
|
||||
var internalPropName = '_' + (uidCounter++) + property;
|
||||
|
||||
if (target.hasOwnProperty(property)) {
|
||||
Object.defineProperty(target, internalPropName, {
|
||||
value: originalValue,
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
|
||||
//then we create accessor method for our 'hidden' property,
|
||||
// that dispatch changesRecords when the value is updated
|
||||
Object.defineProperty(target, property, {
|
||||
get: function () {
|
||||
return this[internalPropName];
|
||||
},
|
||||
set: function (value) {
|
||||
if (!sameValue(value, this[internalPropName])) {
|
||||
var oldValue = this[internalPropName];
|
||||
Object.defineProperty(this, internalPropName, {
|
||||
value: value,
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
var notifier = Object.getNotifier(this);
|
||||
notifier.notify({ type: 'update', name: property, oldValue: oldValue });
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// call defineObservableProperty for each property name passed as 'rest argument'
|
||||
|
||||
/**
|
||||
* Define observable properties on the given object an return it.
|
||||
*
|
||||
* @param {Object} target
|
||||
* @param {...string} properties
|
||||
* @returns {Object}
|
||||
*/
|
||||
ObserveUtils.defineObservableProperties = function defineObservableProperties(target, properties) {
|
||||
if (Object(target) !== target) {
|
||||
throw new TypeError('target must be an Object, given ' + target);
|
||||
}
|
||||
properties = arrSlice(arguments, 1);
|
||||
while (properties.length > 0) {
|
||||
var property = properties.shift(),
|
||||
descriptor = getPropertyDescriptor(target, property);
|
||||
|
||||
if (!descriptor || !isAccessorDescriptor(descriptor)) {
|
||||
var originalValue = descriptor && descriptor.value;
|
||||
defineObservableProperty(target, property, originalValue);
|
||||
}
|
||||
}
|
||||
return target;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// List Implementation
|
||||
// ------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @param length
|
||||
* @returns {*}
|
||||
* @constructor
|
||||
* @function
|
||||
*/
|
||||
function List(length) {
|
||||
if (arguments.length === 0) {
|
||||
length = 0;
|
||||
}
|
||||
|
||||
// in this case we create a list with a given length
|
||||
if (arguments.length <= 1 && typeof length === 'number') {
|
||||
if (this instanceof List) {
|
||||
this.length = length;
|
||||
}
|
||||
else {
|
||||
return new List(length);
|
||||
}
|
||||
}
|
||||
else {
|
||||
//here we create a list with initial values
|
||||
if (!(this instanceof List)) {
|
||||
return List.fromArray(arrSlice(arguments));
|
||||
}
|
||||
else {
|
||||
for (var i = 0, l = arguments.length ; i < l ; i++) {
|
||||
this[i] = arguments[i];
|
||||
}
|
||||
this.length = arguments.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Observe a list
|
||||
* @param {List} list
|
||||
* @param {function} observer
|
||||
*/
|
||||
List.observe = function observe(list, observer) {
|
||||
Object.observe(list, observer, ['add', 'update', 'delete', 'splice']);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Unobserve a list
|
||||
* @param {List} list
|
||||
* @param {function} observer
|
||||
*/
|
||||
List.unobserve = function unobserve(list, observer) {
|
||||
Object.unobserve(list, observer);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a list from a given array
|
||||
* @param array
|
||||
* @returns {List}
|
||||
*/
|
||||
List.fromArray = function fromArray(array) {
|
||||
if (!Array.isArray(array)) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
var list = new List();
|
||||
for (var i = 0, l = array.length ; i < l ; i++) {
|
||||
list[i] = array[i];
|
||||
}
|
||||
list.length = array.length;
|
||||
return list;
|
||||
};
|
||||
|
||||
Object.defineProperties(List.prototype, {
|
||||
/**
|
||||
* hidden value holder for the length property
|
||||
* @private
|
||||
*/
|
||||
'_length' : {
|
||||
value : 0,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
writable: true
|
||||
},
|
||||
/**
|
||||
* the length of the list
|
||||
* @property {number} length
|
||||
*/
|
||||
'length' : {
|
||||
get : function () {
|
||||
return this._length;
|
||||
},
|
||||
set : function (value) {
|
||||
value = isPositiveFiniteInteger(value, 'Invalid list length : $');
|
||||
var notifier = Object.getNotifier(this),
|
||||
oldValue = this._length,
|
||||
removed = [],
|
||||
self = this;
|
||||
if (value !== oldValue) {
|
||||
notifier.performChange('splice', function () {
|
||||
Object.defineProperty(self, '_length', {
|
||||
value : value,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
|
||||
var returnValue;
|
||||
if (oldValue > value) {
|
||||
//delete values if the length have been decreased
|
||||
for (var i = value; i < oldValue; i++) {
|
||||
removed.push(self[i]);
|
||||
self.delete(i);
|
||||
}
|
||||
returnValue = {
|
||||
index : value,
|
||||
removed : removed,
|
||||
addedCount: 0
|
||||
};
|
||||
} else {
|
||||
returnValue = {
|
||||
index : oldValue,
|
||||
removed : removed,
|
||||
addedCount: value - oldValue
|
||||
};
|
||||
}
|
||||
notifier.notify({ type: 'update', name: 'length', oldValue: oldValue });
|
||||
|
||||
return returnValue;
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
enumerable: true,
|
||||
configurable : true
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Returns an Array copy of the list
|
||||
* @returns {Array}
|
||||
*/
|
||||
List.prototype.toArray = function toArray() {
|
||||
return arrSlice(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an string representation of the list
|
||||
* @returns {string}
|
||||
*/
|
||||
List.prototype.toString = function toString() {
|
||||
return this.toArray().toString();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns an json representation of the list
|
||||
* @returns {string}
|
||||
*/
|
||||
List.prototype.toJSON = function toJSON() {
|
||||
return this.toArray();
|
||||
};
|
||||
|
||||
/**
|
||||
* set the givent value at the specified index.
|
||||
* @param {number} index
|
||||
* @param {*} value
|
||||
* @return {*}
|
||||
*/
|
||||
List.prototype.set = function set(index, value) {
|
||||
index = isPositiveFiniteInteger(index, 'Invalid index : $');
|
||||
|
||||
var notifier = Object.getNotifier(this),
|
||||
len = this.length,
|
||||
self = this;
|
||||
if (index >= len) {
|
||||
notifier.performChange('splice', function () {
|
||||
self[index] = value;
|
||||
notifier.notify({ type: 'add', name: index});
|
||||
Object.defineProperty(self, '_length', {
|
||||
value : index + 1,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
notifier.notify({ type: 'update', name: 'length', oldValue: len });
|
||||
|
||||
return {
|
||||
index : len,
|
||||
removed : [],
|
||||
addedCount: self.length - len
|
||||
};
|
||||
});
|
||||
}
|
||||
else if (!sameValue(value, this[index])) {
|
||||
var oldValue = this[index];
|
||||
this[index] = value;
|
||||
notifier.notify({ type: 'update', name: index, oldValue: oldValue });
|
||||
}
|
||||
return value;
|
||||
};
|
||||
|
||||
/**
|
||||
* delete the value at the specified index.
|
||||
* @param {number} index
|
||||
* @return {boolean}
|
||||
*/
|
||||
List.prototype.delete = function del(index) {
|
||||
index = isPositiveFiniteInteger(index, 'Invalid index : $');
|
||||
if (this.hasOwnProperty(index)) {
|
||||
var oldValue = this[index];
|
||||
if (delete this[index]) {
|
||||
var notifier = Object.getNotifier(this);
|
||||
notifier.notify({ type: 'delete', name: index, oldValue: oldValue });
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* create a new list resulting of the concatenation of all the List and array
|
||||
* passed as parameter with the addition of other values passed as parameter
|
||||
* @param {...*} args
|
||||
* @return {List}
|
||||
*/
|
||||
List.prototype.concat = function concat(args) {
|
||||
args = arrMap(arguments, function (item) {
|
||||
return (item instanceof List) ? item.toArray() : item;
|
||||
});
|
||||
return List.fromArray(Array.prototype.concat.apply(this.toArray(), args));
|
||||
};
|
||||
|
||||
/**
|
||||
* Joins all elements of a List into a string.
|
||||
* @param {string} [separator]
|
||||
* @return {string}
|
||||
*/
|
||||
List.prototype.join = function join(separator) {
|
||||
return this.toArray().join(separator);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Removes the last element from a List and returns that element.
|
||||
* @return {*}
|
||||
*/
|
||||
List.prototype.pop = function pop() {
|
||||
if (Object(this) !== this) {
|
||||
throw new TypeError('this mus be an object given : ' + this);
|
||||
}
|
||||
var len = isPositiveFiniteInteger(this.length, 'this must have a finite integer property \'length\', given : $');
|
||||
if (len === 0) {
|
||||
return void(0);
|
||||
} else {
|
||||
var newLen = len - 1,
|
||||
element = this[newLen],
|
||||
notifier = Object.getNotifier(this),
|
||||
self = this;
|
||||
notifier.performChange('splice', function () {
|
||||
delete self[newLen];
|
||||
notifier.notify({ type: 'delete', name: newLen, oldValue: element });
|
||||
Object.defineProperty(self, '_length', {
|
||||
value : newLen,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
notifier.notify({ type: 'update', name: 'length', oldValue: len });
|
||||
|
||||
return {
|
||||
index : newLen,
|
||||
removed : [element],
|
||||
addedCount: 0
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
return element;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Mutates a List by appending the given elements and returning the new length of the array.
|
||||
* @param {...*} items
|
||||
* @return {number}
|
||||
*/
|
||||
List.prototype.push = function push() {
|
||||
if (arguments.length > 0) {
|
||||
var argumentsLength = arguments.length,
|
||||
elements = arguments,
|
||||
len = this.length,
|
||||
notifier = Object.getNotifier(this),
|
||||
self = this,
|
||||
i, index;
|
||||
notifier.performChange('splice', function () {
|
||||
for (i = 0; i < argumentsLength; i++) {
|
||||
index = len + i;
|
||||
// avoid the usage of the set function and manually
|
||||
// set the value and notify the changes to avoid the notification of
|
||||
// multiple length modification
|
||||
self[index] = elements[i];
|
||||
notifier.notify({
|
||||
type : 'add',
|
||||
name : index
|
||||
});
|
||||
}
|
||||
Object.defineProperty(self, '_length', {
|
||||
value : len + argumentsLength,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
notifier.notify({ type: 'update', name: 'length', oldValue: len });
|
||||
return {
|
||||
index : len,
|
||||
removed : [],
|
||||
addedCount: argumentsLength
|
||||
};
|
||||
});
|
||||
}
|
||||
return this.length;
|
||||
};
|
||||
|
||||
/**
|
||||
* Reverses a List in place. The first List element becomes the last and the last becomes the first.
|
||||
* @return {List}
|
||||
*/
|
||||
List.prototype.reverse = function reverse() {
|
||||
var copy = this.toArray(),
|
||||
arr = copy.slice().reverse();
|
||||
|
||||
for (var i = 0, l = arr.length; i < l; i++) {
|
||||
this.set(i, arr[i]);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the first element from a List and returns that element. This method changes the length of the List.
|
||||
* @return {*}
|
||||
*/
|
||||
List.prototype.shift = function () {
|
||||
if (this.length === 0) {
|
||||
return void(0);
|
||||
}
|
||||
|
||||
var arr = this.toArray(),
|
||||
element = arr.shift(),
|
||||
notifier = Object.getNotifier(this),
|
||||
self = this, len = this.length;
|
||||
notifier.performChange('splice', function () {
|
||||
for (var i = 0, l = arr.length; i < l; i++) {
|
||||
self.set(i, arr[i]);
|
||||
}
|
||||
self.delete(len - 1);
|
||||
|
||||
Object.defineProperty(self, '_length', {
|
||||
value : len - 1,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
notifier.notify({ type: 'update', name: 'length', oldValue: len });
|
||||
|
||||
return {
|
||||
index : 0,
|
||||
removed : [element],
|
||||
addedCount: 0
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
return element;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a shallow copy of a portion of an List.
|
||||
* @param {number} [start]
|
||||
* @param {number} [end]
|
||||
* @return {List}
|
||||
*/
|
||||
List.prototype.slice = function (start, end) {
|
||||
return List.fromArray(this.toArray().slice(start, end));
|
||||
};
|
||||
|
||||
/**
|
||||
* Sorts the elements of a List in place and returns the List.
|
||||
* @param {function} [compareFn]
|
||||
* @return {List}
|
||||
*/
|
||||
List.prototype.sort = function (compareFn) {
|
||||
var copy = this.toArray(),
|
||||
arr = copy.slice().sort(compareFn);
|
||||
for (var i = 0, l = arr.length; i < l; i++) {
|
||||
this.set(i, arr[i]);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Changes the content of a List, adding new elements while removing old elements.
|
||||
* @return {List}
|
||||
*/
|
||||
List.prototype.splice = function () {
|
||||
var returnValue = [],
|
||||
argumentsLength = arguments.length;
|
||||
|
||||
if (argumentsLength > 0) {
|
||||
var arr = this.toArray(),
|
||||
notifier = Object.getNotifier(this),
|
||||
len = this.length,
|
||||
self = this,
|
||||
index = arguments[0],
|
||||
i, l;
|
||||
|
||||
returnValue = Array.prototype.splice.apply(arr, arguments);
|
||||
notifier.performChange('splice', function () {
|
||||
for (i = 0, l = arr.length; i < l; i++) {
|
||||
var oldValue = self[i];
|
||||
if (!sameValue(oldValue, arr[i])) {
|
||||
self[i] = arr[i];
|
||||
notifier.notify(
|
||||
i >= len ?
|
||||
{type : 'add', name : i}:
|
||||
{type : 'update', name : i, oldValue : oldValue}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (len !== arr.length) {
|
||||
if (len > arr.length) {
|
||||
//delete values if the length have been decreased
|
||||
for (i = arr.length; i < len; i++) {
|
||||
self.delete(i);
|
||||
}
|
||||
}
|
||||
|
||||
Object.defineProperty(self, '_length', {
|
||||
value : arr.length,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
notifier.notify({ type: 'update', name: 'length', oldValue: len });
|
||||
}
|
||||
return {
|
||||
index : index,
|
||||
removed : returnValue,
|
||||
addedCount: argumentsLength >= 2 ? argumentsLength - 2 : 0
|
||||
};
|
||||
});
|
||||
|
||||
}
|
||||
return List.fromArray(returnValue);
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds one or more elements to the beginning of a List and returns the new length of the List.
|
||||
* @return {number}
|
||||
*/
|
||||
List.prototype.unshift = function () {
|
||||
var argumentsLength = arguments.length;
|
||||
if (argumentsLength > 0) {
|
||||
var arr = this.toArray(),
|
||||
notifier = Object.getNotifier(this),
|
||||
len = this.length,
|
||||
self = this;
|
||||
|
||||
Array.prototype.unshift.apply(arr, arguments);
|
||||
notifier.performChange('splice', function () {
|
||||
for (var i = 0, l = arr.length; i < l; i++) {
|
||||
var oldValue = self[i];
|
||||
if (!sameValue(oldValue, arr[i])) {
|
||||
// avoid the usage of the set function and manually
|
||||
// set the value and notify the changes to avoid the notification of
|
||||
// multiple length modification
|
||||
self[i] = arr[i];
|
||||
notifier.notify(
|
||||
i >= len ?
|
||||
{type : 'add', name : i}:
|
||||
{type : 'update', name : i, oldValue : oldValue}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (len !== arr.length) {
|
||||
if (len > arr.length) {
|
||||
//delete values if the length have been decreased
|
||||
for (i = arr.length; i < len; i++) {
|
||||
self.delete(i);
|
||||
}
|
||||
}
|
||||
Object.defineProperty(self, '_length', {
|
||||
value : arr.length,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
notifier.notify({ type: 'update', name: 'length', oldValue: len });
|
||||
}
|
||||
|
||||
return {
|
||||
index : 0,
|
||||
removed : [],
|
||||
addedCount: argumentsLength
|
||||
};
|
||||
});
|
||||
|
||||
}
|
||||
return this.length;
|
||||
};
|
||||
|
||||
/**
|
||||
* Apply a function against an accumulator and each value of the List (from left-to-right) as to reduce it to a single value.
|
||||
* @param {function} callback
|
||||
* @param {Object} [initialValue]
|
||||
* @return {Object}
|
||||
*/
|
||||
List.prototype.reduce = Array.prototype.reduce;
|
||||
|
||||
/**
|
||||
* Apply a function simultaneously against two values of the array (from right-to-left) as to reduce it to a single value.
|
||||
* @param {function} callback
|
||||
* @param {Object} [initialValue]
|
||||
* @return {Object}
|
||||
*/
|
||||
List.prototype.reduceRight = Array.prototype.reduceRight;
|
||||
|
||||
/**
|
||||
* Returns the first index at which a given element can be found in the List, or -1 if it is not present.
|
||||
* @param {Object} searchElement
|
||||
* @param {number} [fromIndex]
|
||||
* @return {number}
|
||||
*/
|
||||
List.prototype.indexOf = Array.prototype.indexOf;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param {Object} searchElement
|
||||
* @param {number} [fromIndex]
|
||||
* @return {number}
|
||||
*/
|
||||
List.prototype.lastIndexOf = Array.prototype.lastIndexOf;
|
||||
|
||||
/**
|
||||
* Tests whether all elements in the List pass the test implemented by the provided function.
|
||||
* @param {function} callback
|
||||
* @param {Object} [thisObject]
|
||||
* @return {boolean}
|
||||
*/
|
||||
List.prototype.every = Array.prototype.every;
|
||||
|
||||
/**
|
||||
* Creates a new List with all elements that pass the test implemented by the provided function
|
||||
* @param {function} callback
|
||||
* @param {Object} [thisObject]
|
||||
* @return {List}
|
||||
*/
|
||||
List.prototype.filter = function (callback, thisObject) {
|
||||
return List.fromArray(this.toArray().filter(callback, thisObject));
|
||||
};
|
||||
|
||||
/**
|
||||
* Executes a provided function once per List element.
|
||||
* @param {function} callback
|
||||
* @param {Object} [thisObject]
|
||||
* @return {void}
|
||||
*/
|
||||
List.prototype.forEach = Array.prototype.forEach;
|
||||
|
||||
/**
|
||||
* Creates a new List with the results of calling a provided function on every element in this List.
|
||||
* @param {function} callback
|
||||
* @param {Object} [thisObject]
|
||||
* @return {List}
|
||||
*/
|
||||
List.prototype.map = function (callback, thisObject) {
|
||||
return List.fromArray(this.toArray().map(callback, thisObject));
|
||||
};
|
||||
|
||||
/**
|
||||
* Tests whether some element in the List passes the test implemented by the provided function.
|
||||
* @param {function} callback
|
||||
* @param {Object} [thisObject]
|
||||
* @return {boolean}
|
||||
*/
|
||||
List.prototype.some = Array.prototype.some;
|
||||
|
||||
ObserveUtils.List = List;
|
||||
|
||||
})(this);
|
||||
45
gaia/distros/spark/apps/customizer/components/observe-utils/package.json
Executable file
45
gaia/distros/spark/apps/customizer/components/observe-utils/package.json
Executable file
|
|
@ -0,0 +1,45 @@
|
|||
{
|
||||
"name": "observe-utils",
|
||||
"description": "A set of utilities for the observe-shim",
|
||||
"version": "0.3.2",
|
||||
"keywords": [
|
||||
"observe",
|
||||
"observe-utils",
|
||||
"data binding"
|
||||
],
|
||||
"author": {
|
||||
"name": "Kap IT",
|
||||
"email": "contact@kapit.fr",
|
||||
"url": "http://www.kapit.fr/"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "François de Campredon",
|
||||
"email": "fdecampredon@kapit.fr",
|
||||
"url": "http://francois.de-campredon.fr/"
|
||||
}
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/kapit/observe-utils.git"
|
||||
},
|
||||
"main": "lib/observe-utils.js",
|
||||
"scripts": {
|
||||
"test": "grunt test"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"matchdep": "~0.1.1",
|
||||
"grunt": "~0.4.0",
|
||||
"grunt-contrib-jshint": "~0.1.1",
|
||||
"grunt-mocha": "~0.2.3",
|
||||
"observe-shim": "~0.4.0",
|
||||
"sinon": "~1.7.3",
|
||||
"expect.js": "~0.2.0",
|
||||
"grunt-mocha-test": "~0.7.0"
|
||||
},
|
||||
"licenses": {
|
||||
"type": "Apache-2.0",
|
||||
"url": "http://www.apache.org/licenses/LICENSE-2.0"
|
||||
}
|
||||
}
|
||||
1256
gaia/distros/spark/apps/customizer/components/observe-utils/test/List.js
Executable file
1256
gaia/distros/spark/apps/customizer/components/observe-utils/test/List.js
Executable file
File diff suppressed because it is too large
Load diff
57
gaia/distros/spark/apps/customizer/components/observe-utils/test/bug.js
Executable file
57
gaia/distros/spark/apps/customizer/components/observe-utils/test/bug.js
Executable file
|
|
@ -0,0 +1,57 @@
|
|||
// Copyright 2012 Kap IT (http://www.kapit.fr/)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the 'License');
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an 'AS IS' BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Author : François de Campredon (http://francois.de-campredon.fr/),
|
||||
|
||||
/*global describe, it, sinon, expect, beforeEach, ObserveUtils */
|
||||
|
||||
|
||||
describe('observer-utils bugs', function () {
|
||||
'use strict';
|
||||
|
||||
var List = ObserveUtils.List;
|
||||
|
||||
var list, notifySpy;
|
||||
beforeEach(function () {
|
||||
list = List(1, 2);
|
||||
var notifier = Object.getNotifier(list);
|
||||
notifySpy = notifier.notify = sinon.spy();
|
||||
});
|
||||
|
||||
function getNotifiedChangesRecords() {
|
||||
return notifySpy.args.map(function (arr) {
|
||||
return arr[0];
|
||||
});
|
||||
}
|
||||
|
||||
function getNotifiedChangesRecordsWithoutSplice() {
|
||||
return getNotifiedChangesRecords().filter(function (record) {
|
||||
return record.type !== 'splice';
|
||||
});
|
||||
}
|
||||
|
||||
// issues #1 (https://github.com/KapIT/observe-utils/issues/1)
|
||||
it('Method like unshift create change records for index that does not have change', function () {
|
||||
list.unshift(1);
|
||||
expect(getNotifiedChangesRecordsWithoutSplice()).to.be.eql([
|
||||
{type: 'update', name: '1', oldValue: 2},
|
||||
{type: 'add', name: '2'},
|
||||
{type: 'update', name: 'length', oldValue: 2}
|
||||
]);
|
||||
});
|
||||
|
||||
it('Method like splice create change records for index that does not have change', function () {
|
||||
list.splice(0, 1, 1);
|
||||
expect(getNotifiedChangesRecordsWithoutSplice()).to.be.eql([]);
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,181 @@
|
|||
/*global ObserveUtils, describe, it, expect , sinon*/
|
||||
|
||||
describe('defineObservableProperties', function () {
|
||||
'use strict';
|
||||
|
||||
function getPropertyDescriptor(target, name) {
|
||||
var pd = Object.getOwnPropertyDescriptor(target, name);
|
||||
var proto = Object.getPrototypeOf(target);
|
||||
while (typeof pd === 'undefined' && proto !== null) {
|
||||
pd = Object.getOwnPropertyDescriptor(proto, name);
|
||||
proto = Object.getPrototypeOf(proto);
|
||||
}
|
||||
return pd;
|
||||
}
|
||||
|
||||
function testIsObject(testFunc) {
|
||||
expect(function () {
|
||||
testFunc(5);
|
||||
}).to.throwException(function (e) {
|
||||
expect(e).to.be.a(TypeError);
|
||||
});
|
||||
|
||||
expect(function () {
|
||||
testFunc('string');
|
||||
}).to.throwException(function (e) {
|
||||
expect(e).to.be.a(TypeError);
|
||||
});
|
||||
|
||||
expect(function () {
|
||||
testFunc(NaN);
|
||||
}).to.throwException(function (e) {
|
||||
expect(e).to.be.a(TypeError);
|
||||
});
|
||||
|
||||
expect(function () {
|
||||
testFunc(null);
|
||||
}).to.throwException(function (e) {
|
||||
expect(e).to.be.a(TypeError);
|
||||
});
|
||||
|
||||
expect(function () {
|
||||
testFunc(undefined);
|
||||
}).to.throwException(function (e) {
|
||||
expect(e).to.be.a(TypeError);
|
||||
});
|
||||
|
||||
expect(function () {
|
||||
testFunc({});
|
||||
}).to.not.throwException();
|
||||
|
||||
expect(function () {
|
||||
testFunc(function () {});
|
||||
}).to.not.throwException();
|
||||
}
|
||||
|
||||
|
||||
|
||||
it('should throw an error when passing an non object at first parameter', function () {
|
||||
testIsObject(function (target) {
|
||||
ObserveUtils.defineObservableProperties(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('should define getter/setter on object', function () {
|
||||
var object = {};
|
||||
|
||||
ObserveUtils.defineObservableProperties(object, 'property');
|
||||
expect(object).to.have.property('property');
|
||||
|
||||
var descriptor = Object.getOwnPropertyDescriptor(object, 'property');
|
||||
expect(descriptor).to.have.property('get');
|
||||
expect(descriptor).to.have.property('set');
|
||||
});
|
||||
|
||||
it('should define multiple property on rest parameter', function () {
|
||||
var object = {};
|
||||
ObserveUtils.defineObservableProperties(object, 'property', 'property1', 'property2');
|
||||
|
||||
expect(object).to.have.property('property');
|
||||
expect(object).to.have.property('property1');
|
||||
expect(object).to.have.property('property2');
|
||||
});
|
||||
|
||||
|
||||
it('should conserve the original value', function () {
|
||||
var value = {};
|
||||
var object = {property: value};
|
||||
ObserveUtils.defineObservableProperties(object, 'property');
|
||||
|
||||
expect(object.property).to.be.equal(value);
|
||||
});
|
||||
|
||||
it('should not redefine property with getter/setter', function () {
|
||||
|
||||
var getter = function () {
|
||||
};
|
||||
var setter = function () {
|
||||
};
|
||||
|
||||
var object = {};
|
||||
Object.defineProperty(object, 'property', {
|
||||
get: getter,
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
});
|
||||
|
||||
ObserveUtils.defineObservableProperties(object, 'property');
|
||||
expect(Object.getOwnPropertyDescriptor(object, 'property').get).to.be.equal(getter);
|
||||
|
||||
var object1 = {};
|
||||
Object.defineProperty(object1, 'property', {
|
||||
set: setter,
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
});
|
||||
expect(Object.getOwnPropertyDescriptor(object1, 'property').set).to.be.equal(setter);
|
||||
});
|
||||
|
||||
it('should not redefine property with getter/setter defined in the prototype chain', function () {
|
||||
|
||||
var getter = function () {
|
||||
};
|
||||
var proto = {};
|
||||
|
||||
Object.defineProperty(proto, 'property', {
|
||||
get: getter,
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
});
|
||||
|
||||
var object = Object.create(proto);
|
||||
|
||||
expect(Object.getOwnPropertyDescriptor(object, 'property')).to.be.equal(undefined);
|
||||
expect(getPropertyDescriptor(object, 'property').get).to.be.equal(getter);
|
||||
});
|
||||
|
||||
|
||||
it('should not define other enumerable property', function () {
|
||||
|
||||
var object = {};
|
||||
|
||||
ObserveUtils.defineObservableProperties(object, 'property');
|
||||
expect(object).to.be.eql({property: undefined});
|
||||
|
||||
});
|
||||
|
||||
it('should define property that notify when they are updated', function () {
|
||||
|
||||
var object = {},
|
||||
notifier = Object.getNotifier(object);
|
||||
notifier.notify = sinon.spy();
|
||||
ObserveUtils.defineObservableProperties(object, 'property');
|
||||
object.property = 5;
|
||||
|
||||
expect(notifier.notify.calledOnce).to.be.ok();
|
||||
expect(notifier.notify.args[0][0]).to.be.eql({
|
||||
type: 'update',
|
||||
name: 'property',
|
||||
oldValue: undefined
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
it('should define property that notify when they are updated, only if value has changed', function () {
|
||||
var object = {},
|
||||
notifier = Object.getNotifier(object);
|
||||
notifier.notify = sinon.spy();
|
||||
ObserveUtils.defineObservableProperties(object, 'property');
|
||||
object.property = 5;
|
||||
object.property = 5;
|
||||
|
||||
expect(notifier.notify.calledOnce).to.be.ok();
|
||||
expect(notifier.notify.args[0][0]).to.be.eql({
|
||||
type: 'update',
|
||||
name: 'property',
|
||||
oldValue: undefined
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
29
gaia/distros/spark/apps/customizer/components/observe-utils/test/index.html
Executable file
29
gaia/distros/spark/apps/customizer/components/observe-utils/test/index.html
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="../components/mocha/mocha.css" type="text/css" >
|
||||
|
||||
<script type="text/javascript" src="../components/expect/expect.js" ></script>
|
||||
<script type="text/javascript" src="../components/mocha/mocha.js" ></script>
|
||||
<script type="text/javascript" src="../components/sinon/index.js" ></script>
|
||||
<script type="text/javascript" src="../components/es5-shim/es5-shim.js"></script>
|
||||
<script type="text/javascript" src="../components/observe-shim/lib/observe-shim.js" ></script>
|
||||
<script type="text/javascript" src="../lib/observe-utils.js" ></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha"></div>
|
||||
<script type="text/javascript">
|
||||
mocha.setup("bdd");
|
||||
</script>
|
||||
<script src="defineObservableProperties.js" type="text/javascript"></script>
|
||||
<script src="List.js" type="text/javascript"></script>
|
||||
<script src="bug.js" type="text/javascript" ></script>
|
||||
<script type="text/javascript" >
|
||||
if ( typeof window.PHANTOMJS === "undefined") {
|
||||
mocha.run();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
// exported expect, sinon
|
||||
|
||||
global.expect = require('expect.js');
|
||||
global.sinon = require('sinon');
|
||||
require('observe-shim');
|
||||
global.ObserveUtils = require('../lib/observe-utils');
|
||||
require('./defineObservableProperties');
|
||||
require('./list');
|
||||
require('./bug');
|
||||
Loading…
Reference in a new issue