cleaning up (1)
This commit is contained in:
parent
9b582fc795
commit
7696864841
17
.codio
Normal file
17
.codio
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
// Configure your Run and Preview buttons here.
|
||||
|
||||
// Run button configuration
|
||||
"commands": {
|
||||
"browser": "gulp browser",
|
||||
"test&compile": "gulp"
|
||||
},
|
||||
|
||||
// Preview button configuration
|
||||
"preview": {
|
||||
"Project Index (static)": "https://{{domain}}/{{index}}",
|
||||
"Current File (static)": "https://{{domain}}/{{filepath}}",
|
||||
"Box URL": "http://{{domain}}:3000/",
|
||||
"Box URL SSL": "https://{{domain}}:9500/"
|
||||
}
|
||||
}
|
64
.settings
Normal file
64
.settings
Normal file
@ -0,0 +1,64 @@
|
||||
[editor]
|
||||
; enter your editor preferences here...
|
||||
|
||||
[view-javascript-code]
|
||||
; enter your view-javascript-code preferences here...
|
||||
|
||||
[emmet]
|
||||
; enter your emmet preferences here...
|
||||
|
||||
[git]
|
||||
; enter your git preferences here...
|
||||
|
||||
[terminal]
|
||||
; enter your terminal preferences here...
|
||||
|
||||
[preview]
|
||||
index_file = examples/PeerJs-Json/index.html
|
||||
; enter your preview preferences here...
|
||||
|
||||
[search]
|
||||
; enter your search preferences here...
|
||||
|
||||
[ide]
|
||||
; enter your ide preferences here...
|
||||
|
||||
[code-beautifier]
|
||||
; enter your code-beautifier preferences here...
|
||||
|
||||
[guides]
|
||||
; enter your guides preferences here...
|
||||
|
||||
[settings]
|
||||
; enter your settings preferences here...
|
||||
|
||||
[account]
|
||||
; enter your account preferences here...
|
||||
|
||||
[sync-structure]
|
||||
; enter your sync-structure preferences here...
|
||||
|
||||
[account-settings]
|
||||
; enter your account-settings preferences here...
|
||||
|
||||
[install-software]
|
||||
; enter your install-software preferences here...
|
||||
|
||||
[project]
|
||||
; enter your project preferences here...
|
||||
|
||||
[education]
|
||||
; enter your education preferences here...
|
||||
|
||||
[codio-bower]
|
||||
; enter your codio-bower preferences here...
|
||||
|
||||
[deployment]
|
||||
; enter your deployment preferences here...
|
||||
|
||||
[container]
|
||||
; enter your container preferences here...
|
||||
|
||||
[dashboard]
|
||||
; enter your dashboard preferences here...
|
||||
|
2
Frameworks/index.js
Normal file
2
Frameworks/index.js
Normal file
File diff suppressed because one or more lines are too long
@ -1,5 +1,5 @@
|
||||
|
||||
# 
|
||||
# 
|
||||
|
||||
A Real-Time web framework that manages concurrency control for arbitrary data structures.
|
||||
Yatta! provides similar functionality as [ShareJs](https://github.com/share/ShareJS) and [OpenCoweb](https://github.com/opencoweb/coweb),
|
||||
|
@ -25,6 +25,6 @@
|
||||
"tests"
|
||||
],
|
||||
"dependencies": {
|
||||
"peerjs": "~0.3.14",
|
||||
"peerjs": "~0.3.14"
|
||||
}
|
||||
}
|
||||
|
32
bower_components/observe-js/.bower.json
vendored
Normal file
32
bower_components/observe-js/.bower.json
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "observe-js",
|
||||
"homepage": "https://github.com/Polymer/observe-js",
|
||||
"authors": [
|
||||
"The Polymer Authors"
|
||||
],
|
||||
"description": "A library for observing Arrays, Objects and PathValues",
|
||||
"main": "src/observe.js",
|
||||
"keywords": [
|
||||
"Object.observe"
|
||||
],
|
||||
"license": "BSD",
|
||||
"private": true,
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"bower_components",
|
||||
"test",
|
||||
"tests"
|
||||
],
|
||||
"version": "0.5.1",
|
||||
"_release": "0.5.1",
|
||||
"_resolution": {
|
||||
"type": "version",
|
||||
"tag": "0.5.1",
|
||||
"commit": "d530515b4afe7d0a6b61c06f1a6c64f07bcbbf57"
|
||||
},
|
||||
"_source": "git://github.com/Polymer/observe-js.git",
|
||||
"_target": "~0.5.1",
|
||||
"_originalSource": "observe-js",
|
||||
"_direct": true
|
||||
}
|
9
bower_components/observe-js/AUTHORS
vendored
Normal file
9
bower_components/observe-js/AUTHORS
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
# Names should be added to this file with this pattern:
|
||||
#
|
||||
# For individuals:
|
||||
# Name <email address>
|
||||
#
|
||||
# For organizations:
|
||||
# Organization <fnmatch pattern>
|
||||
#
|
||||
Google Inc. <*@google.com>
|
203
bower_components/observe-js/README.md
vendored
Normal file
203
bower_components/observe-js/README.md
vendored
Normal file
@ -0,0 +1,203 @@
|
||||
[](http://build.chromium.org/p/client.polymer/waterfall) [](https://github.com/igrigorik/ga-beacon)
|
||||
|
||||
## Learn the tech
|
||||
|
||||
### Why observe-js?
|
||||
|
||||
observe-js is a library for observing changes in JavaScript data. It exposes a high-level API and uses Object.observe if available, and otherwise performs dirty-checking. observe-js requires ECMAScript 5.
|
||||
|
||||
### Observable
|
||||
|
||||
observe-js implements a set of observers (PathObserver, ArrayObserver, ObjectObserver, CompoundObserver, ObserverTransform) which all implement the Observable interface:
|
||||
|
||||
```JavaScript
|
||||
{
|
||||
// Begins observation. Value changes will be reported by invoking |changeFn| with |opt_receiver| as
|
||||
// the target, if provided. Returns the initial value of the observation.
|
||||
open: function(changeFn, opt_receiver) {},
|
||||
|
||||
// Report any changes now (does nothing if there are no changes to report).
|
||||
deliver: function() {},
|
||||
|
||||
// If there are changes to report, ignore them. Returns the current value of the observation.
|
||||
discardChanges: function() {},
|
||||
|
||||
// Ends observation. Frees resources and drops references to observed objects.
|
||||
close: function() {}
|
||||
}
|
||||
```
|
||||
|
||||
### PathObserver
|
||||
|
||||
PathObserver observes a "value-at-a-path" from a given object:
|
||||
|
||||
```JavaScript
|
||||
var obj = { foo: { bar: 'baz' } };
|
||||
var observer = new PathObserver(obj, 'foo.bar');
|
||||
observer.open(function(newValue, oldValue) {
|
||||
// respond to obj.foo.bar having changed value.
|
||||
});
|
||||
```
|
||||
|
||||
PathObserver will report a change whenever the value obtained by the corresponding path expression (e.g. `obj.foo.bar`) would return a different value.
|
||||
|
||||
PathObserver also exposes a `setValue` method which attempts to update the underlying value. Setting the value does not affect notification state (in other words, a caller sets the value but does not `discardChanges`, the `changeFn` will be notified of the change).
|
||||
|
||||
```JavaScript
|
||||
observer.setValue('boo');
|
||||
assert(obj.foo.bar == 'boo');
|
||||
```
|
||||
|
||||
Notes:
|
||||
* If the path is ever unreachable, the value is considered to be `undefined`.
|
||||
* If the path is empty (e.g. `''`), it is said to be the empty path and its value is its root object.
|
||||
* PathObservation respects values on the prototype chain
|
||||
|
||||
### ArrayObserver
|
||||
|
||||
ArrayObserver observes the index-positions of an Array and reports changes as the minimal set of "splices" which would have had the same effect.
|
||||
|
||||
```JavaScript
|
||||
var arr = [0, 1, 2, 4];
|
||||
var observer = new ArrayObserver(arr);
|
||||
observer.open(function(splices) {
|
||||
// respond to changes to the elements of arr.
|
||||
splices.forEach(function(splice) {
|
||||
splice.index; // index position that the change occurred.
|
||||
splice.removed; // an array of values representing the sequence of elements which were removed
|
||||
splice.addedCount; // the number of elements which were inserted.
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
ArrayObserver also exposes a utility function: `applySplices`. The purpose of `applySplices` is to transform a copy of an old state of an array into a copy of its current state, given the current state and the splices reported from the ArrayObserver.
|
||||
|
||||
```JavaScript
|
||||
AraryObserver.applySplices = function(previous, current, splices) { }
|
||||
```
|
||||
|
||||
### ObjectObserver
|
||||
|
||||
ObjectObserver observes the set of own-properties of an object and their values.
|
||||
|
||||
```JavaScript
|
||||
var myObj = { id: 1, foo: 'bar' };
|
||||
var observer = new ObjectObserver(myObj);
|
||||
observer.open(function(added, removed, changed, getOldValueFn) {
|
||||
// respond to changes to the obj.
|
||||
Object.keys(added).forEach(function(property) {
|
||||
property; // a property which has been been added to obj
|
||||
added[property]; // its value
|
||||
});
|
||||
Object.keys(removed).forEach(function(property) {
|
||||
property; // a property which has been been removed from obj
|
||||
getOldValueFn(property); // its old value
|
||||
});
|
||||
Object.keys(changed).forEach(function(property) {
|
||||
property; // a property on obj which has changed value.
|
||||
changed[property]; // its value
|
||||
getOldValueFn(property); // its old value
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
### CompoundObserver
|
||||
|
||||
CompoundObserver allows simultaneous observation of multiple paths and/or Observables. It reports any and all changes in to the provided `changeFn` callback.
|
||||
|
||||
```JavaScript
|
||||
var obj = {
|
||||
a: 1,
|
||||
b: 2,
|
||||
};
|
||||
|
||||
var otherObj = { c: 3 };
|
||||
|
||||
var observer = new CompoundObserver();
|
||||
observer.addPath(obj, 'a');
|
||||
observer.addObserver(new PathObserver(obj, 'b'));
|
||||
observer.addPath(otherObj, 'c');
|
||||
observer.open(function(newValues, oldValues) {
|
||||
// Use for-in to iterte which values have changed.
|
||||
for (var i in oldValues) {
|
||||
console.log('The ' + i + 'th value changed from: ' + newValues[i] + ' to: ' + oldValues[i]);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
### ObserverTransform
|
||||
|
||||
ObserverTransform is used to dynamically transform observed value(s).
|
||||
|
||||
```JavaScript
|
||||
var obj = { value: 10 };
|
||||
var observer = new PathObserver(obj, 'value');
|
||||
function getValue(value) { return value * 2 };
|
||||
function setValue(value) { return value / 2 };
|
||||
|
||||
var transform = new ObserverTransform(observer, getValue, setValue);
|
||||
|
||||
// returns 20.
|
||||
transform.open(function(newValue, oldValue) {
|
||||
console.log('new: ' + newValue + ', old: ' + oldValue);
|
||||
});
|
||||
|
||||
obj.value = 20;
|
||||
transform.deliver(); // 'new: 40, old: 20'
|
||||
transform.setValue(4); // obj.value === 2;
|
||||
```
|
||||
|
||||
ObserverTransform can also be used to reduce a set of observed values to a single value:
|
||||
|
||||
```JavaScript
|
||||
var obj = { a: 1, b: 2, c: 3 };
|
||||
var observer = new CompoundObserver();
|
||||
observer.addPath(obj, 'a');
|
||||
observer.addPath(obj, 'b');
|
||||
observer.addPath(obj, 'c');
|
||||
var transform = new ObserverTransform(observer, fuction(values) {
|
||||
var value = 0;
|
||||
for (var i = 0; i < values.length; i++)
|
||||
value += values[i]
|
||||
return value;
|
||||
});
|
||||
|
||||
// returns 6.
|
||||
transform.open(function(newValue, oldValue) {
|
||||
console.log('new: ' + newValue + ', old: ' + oldValue);
|
||||
});
|
||||
|
||||
obj.a = 2;
|
||||
obj.c = 10;
|
||||
transform.deliver(); // 'new: 14, old: 6'
|
||||
```
|
||||
|
||||
### Path objects
|
||||
|
||||
A path is an ECMAScript expression consisting only of identifiers (`myVal`), member accesses (`foo.bar`) and key lookup with literal values (`arr[0]` `obj['str-value'].bar.baz`).
|
||||
|
||||
`Path.get('foo.bar.baz')` returns a Path object which represents the path. Path objects have the following API:
|
||||
|
||||
```JavaScript
|
||||
{
|
||||
// Returns the current of the path from the provided object. If eval() is available, a compiled getter will be
|
||||
// used for better performance.
|
||||
getValueFrom: function(obj) { }
|
||||
|
||||
|
||||
// Attempts to set the value of the path from the provided object. Returns true IFF the path was reachable and
|
||||
// set.
|
||||
setValueFrom: function(obj, newValue) { }
|
||||
}
|
||||
```
|
||||
|
||||
Path objects are interned (e.g. `assert(Path.get('foo.bar.baz') === Path.get('foo.bar.baz'));`) and are used internally to avoid excessive parsing of path strings. Observers which take path strings as arguments will also accept Path objects.
|
||||
|
||||
## About delivery of changes
|
||||
|
||||
observe-js is intended for use in environments which implement Object.observe, but it supports use in environments which do not.
|
||||
|
||||
If `Object.observe` is present, and observers have changes to report, their callbacks will be invoked at the end of the current turn (microtask). In a browser environment, this is generally at the end of an event.
|
||||
|
||||
If `Object.observe` is absent, `Platform.performMicrotaskCheckpoint()` must be called to trigger delivery of changes. If `Object.observe` is implemented, `Platform.performMicrotaskCheckpoint()` has no effect.
|
183
bower_components/observe-js/benchmark/benchmark.js
vendored
Normal file
183
bower_components/observe-js/benchmark/benchmark.js
vendored
Normal file
@ -0,0 +1,183 @@
|
||||
/*
|
||||
* Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
|
||||
(function(global) {
|
||||
'use strict';
|
||||
|
||||
function now() {
|
||||
return global.performance && typeof performance.now == 'function' ?
|
||||
performance.now() : Date.now();
|
||||
}
|
||||
|
||||
function checkpoint() {
|
||||
if (global.Platform &&
|
||||
typeof Platform.performMicrotaskCheckpoint == 'function') {
|
||||
Platform.performMicrotaskCheckpoint();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(rafaelw): Add simple Promise polyfill for IE.
|
||||
|
||||
var TESTING_TICKS = 400;
|
||||
var TICKS_PER_FRAME = 16;
|
||||
var MAX_RUNS = 50;
|
||||
|
||||
function Benchmark(testingTicks, ticksPerFrame, maxRuns) {
|
||||
this.testingTicks = testingTicks || TESTING_TICKS;
|
||||
this.ticksPerFrame = ticksPerFrame || TICKS_PER_FRAME;
|
||||
this.maxRuns = maxRuns || 50;
|
||||
this.average = 0;
|
||||
}
|
||||
|
||||
Benchmark.prototype = {
|
||||
// Abstract API
|
||||
setup: function(variation) {},
|
||||
test: function() {
|
||||
throw Error('Not test function found');
|
||||
},
|
||||
cleanup: function() {},
|
||||
|
||||
runOne: function(variation) {
|
||||
this.setup(variation);
|
||||
|
||||
var before = now();
|
||||
this.test(variation);
|
||||
|
||||
var self = this;
|
||||
|
||||
return Promise.resolve().then(function() {
|
||||
checkpoint();
|
||||
|
||||
var after = now();
|
||||
|
||||
self.cleanup(variation);
|
||||
return after - before;
|
||||
});
|
||||
},
|
||||
|
||||
runMany: function(count, variation) {
|
||||
var self = this;
|
||||
|
||||
return new Promise(function(fulfill) {
|
||||
var total = 0;
|
||||
|
||||
function next(time) {
|
||||
if (!count) {
|
||||
fulfill(total);
|
||||
return;
|
||||
}
|
||||
|
||||
self.runOne(variation).then(function(time) {
|
||||
count--;
|
||||
total += time;
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
requestAnimationFrame(next);
|
||||
});
|
||||
},
|
||||
|
||||
runVariation: function(variation, reportFn) {
|
||||
var self = this;
|
||||
reportFn = reportFn || function() {}
|
||||
|
||||
return new Promise(function(fulfill) {
|
||||
self.runMany(3, variation).then(function(time) {
|
||||
return time/3;
|
||||
}).then(function(estimate) {
|
||||
var runsPerFrame = Math.ceil(self.ticksPerFrame / estimate);
|
||||
var frames = Math.ceil(self.testingTicks / self.ticksPerFrame);
|
||||
var maxFrames = Math.ceil(self.maxRuns / runsPerFrame);
|
||||
|
||||
frames = Math.min(frames, maxFrames);
|
||||
var count = 0;
|
||||
var total = 0;
|
||||
|
||||
function next() {
|
||||
if (!frames) {
|
||||
self.average = total / count;
|
||||
self.dispose();
|
||||
fulfill(self.average);
|
||||
return;
|
||||
}
|
||||
|
||||
self.runMany(runsPerFrame, variation).then(function(time) {
|
||||
frames--;
|
||||
total += time;
|
||||
count += runsPerFrame;
|
||||
reportFn(variation, count);
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
run: function(variations, reportFn) {
|
||||
if (!Array.isArray(variations)) {
|
||||
return this.runVariation(variations, reportFn);
|
||||
}
|
||||
|
||||
var self = this;
|
||||
variations = variations.slice();
|
||||
return new Promise(function(fulfill) {
|
||||
var results = [];
|
||||
|
||||
function next() {
|
||||
if (!variations.length) {
|
||||
fulfill(results);
|
||||
return;
|
||||
}
|
||||
|
||||
var variation = variations.shift();
|
||||
self.runVariation(variation, reportFn).then(function(time) {
|
||||
results.push(time);
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function all(benchmarks, variations, statusFn) {
|
||||
return new Promise(function(fulfill) {
|
||||
var results = [];
|
||||
var current;
|
||||
|
||||
function next() {
|
||||
current = benchmarks.shift();
|
||||
|
||||
if (!current) {
|
||||
fulfill(results);
|
||||
return;
|
||||
}
|
||||
|
||||
function update(variation, runs) {
|
||||
statusFn(current, variation, runs);
|
||||
}
|
||||
|
||||
current.run(variations, update).then(function(time) {
|
||||
results.push(time);
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
global.Benchmark = Benchmark;
|
||||
global.Benchmark.all = all;
|
||||
|
||||
})(this);
|
40
bower_components/observe-js/benchmark/d8_benchmarks.js
vendored
Normal file
40
bower_components/observe-js/benchmark/d8_benchmarks.js
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
|
||||
var console = {
|
||||
log: print
|
||||
};
|
||||
|
||||
var requestAnimationFrame = function(callback) {
|
||||
callback();
|
||||
}
|
||||
|
||||
recordCount = 0;
|
||||
|
||||
var alert = print;
|
||||
|
||||
function reportResults(times) {
|
||||
console.log(JSON.stringify(times));
|
||||
}
|
||||
|
||||
function reportStatus(b, variation, count) {
|
||||
console.log(b.objectCount + ' objects, ' + count + ' runs.');
|
||||
}
|
||||
|
||||
var objectCounts = [ 4000, 8000, 16000 ];
|
||||
|
||||
var benchmarks = [];
|
||||
|
||||
objectCounts.forEach(function(objectCount, i) {
|
||||
benchmarks.push(
|
||||
new SetupPathBenchmark('', objectCount));
|
||||
});
|
||||
|
||||
Benchmark.all(benchmarks, 0, reportStatus).then(reportResults);
|
||||
|
181
bower_components/observe-js/benchmark/index.html
vendored
Normal file
181
bower_components/observe-js/benchmark/index.html
vendored
Normal file
@ -0,0 +1,181 @@
|
||||
<html>
|
||||
<!--
|
||||
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
|
||||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
Code distributed by Google as part of the polymer project is also
|
||||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
-->
|
||||
<head>
|
||||
<title>Observation Benchmarks</title>
|
||||
<meta charset="utf-8">
|
||||
<script src="../src/observe.js"></script>
|
||||
<script src="chartjs/Chart.js"></script>
|
||||
<script src="benchmark.js"></script>
|
||||
<script src="observation_benchmark.js"></script>
|
||||
<style>
|
||||
* {
|
||||
font-family: arial, helvetica, sans-serif;
|
||||
font-weight: 400;
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background-color: rgba(0, 0, 0, .1);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Observation Benchmarks</h1>
|
||||
|
||||
<select id="benchmarkSelect">
|
||||
<option>ObjectBenchmark</option>
|
||||
<option>SetupObjectBenchmark</option>
|
||||
<option>ArrayBenchmark</option>
|
||||
<option>SetupArrayBenchmark</option>
|
||||
<option>PathBenchmark</option>
|
||||
<option>SetupPathBenchmark</option>
|
||||
</select>
|
||||
<select id="configSelect">
|
||||
</select>
|
||||
|
||||
<button id="go">Run Benchmarks</button>
|
||||
|
||||
<span>Object Count: </span>
|
||||
<input id="objectCountInput" style="width: 200px" value="4000, 8000, 16000, 32000"><br>
|
||||
<span>Mutation Count: </span>
|
||||
<input id="mutationCountInput" style="width: 200px" value="0, 100, 200, 400, 800, 1600"><br>
|
||||
<br>
|
||||
<span id="status"></span>
|
||||
|
||||
<section style="width: 100%">
|
||||
<article>
|
||||
<div style="display:inline-block; padding-bottom: 20px">
|
||||
Times in ms
|
||||
</div>
|
||||
<div style="display:inline-block">
|
||||
<canvas id="times" width="800" height="400"></canvas>
|
||||
</div>
|
||||
<div style="display:inline-block">
|
||||
<ul id="legendList">
|
||||
</ul>
|
||||
</div>
|
||||
</article>
|
||||
</section>
|
||||
<h3 style="margin-left: 440px">Object Set Size</h3>
|
||||
<script>
|
||||
var benchmark;
|
||||
var goButton = document.getElementById('go');
|
||||
|
||||
var objectCountInput = document.getElementById('objectCountInput');
|
||||
var mutationCountInput = document.getElementById('mutationCountInput');
|
||||
|
||||
var statusSpan = document.getElementById('status');
|
||||
|
||||
var timesCanvas = document.getElementById('times');
|
||||
var benchmarkSelect = document.getElementById('benchmarkSelect');
|
||||
var configSelect = document.getElementById('configSelect');
|
||||
|
||||
function changeBenchmark() {
|
||||
benchmark = window[benchmarkSelect.value];
|
||||
configSelect.textContent = '';
|
||||
benchmark.configs.forEach(function(config) {
|
||||
var option = document.createElement('option');
|
||||
option.textContent = config;
|
||||
configSelect.appendChild(option);
|
||||
});
|
||||
|
||||
document.title = benchmarkSelect.value;
|
||||
}
|
||||
|
||||
benchmarkSelect.addEventListener('change', changeBenchmark);
|
||||
|
||||
changeBenchmark();
|
||||
var ul = document.getElementById('legendList');
|
||||
var colors = [
|
||||
[0, 0, 255],
|
||||
[138,43,226],
|
||||
[165,42,42],
|
||||
[100,149,237],
|
||||
[220,20,60],
|
||||
[184,134,11]
|
||||
].map(function(rgb) {
|
||||
return 'rgba(' + rgb.join(',') + ',.7)';
|
||||
});
|
||||
|
||||
goButton.addEventListener('click', function() {
|
||||
goButton.disabled = true;
|
||||
goButton.textContent = 'Running...';
|
||||
ul.textContent = '';
|
||||
|
||||
var objectCounts = objectCountInput.value.split(',').map(function(val) {
|
||||
return Number(val);
|
||||
});
|
||||
var mutationCounts = mutationCountInput.value.split(',').map(function(val) {
|
||||
return Number(val);
|
||||
});
|
||||
|
||||
mutationCounts.forEach(function(count, i) {
|
||||
var li = document.createElement('li');
|
||||
li.textContent = count + ' mutations.'
|
||||
li.style.color = colors[i];
|
||||
ul.appendChild(li);
|
||||
});
|
||||
|
||||
var results = [];
|
||||
|
||||
function benchmarkComplete(times) {
|
||||
timesArray = [];
|
||||
var index = 0;
|
||||
|
||||
|
||||
mutationCounts.forEach(function(mutationCount, i) {
|
||||
timesArray.push([]);
|
||||
objectCounts.forEach(function(objectCount, j) {
|
||||
timesArray[i][j] = times[j][i];
|
||||
});
|
||||
});
|
||||
|
||||
timesCanvas.height = 400;
|
||||
timesCanvas.width = 800;
|
||||
timesCanvas.setAttribute('style', '');
|
||||
|
||||
var ctx = timesCanvas.getContext("2d");
|
||||
new Chart(ctx).Line({
|
||||
labels: objectCounts,
|
||||
datasets: timesArray.map(function(times, i) {
|
||||
return {
|
||||
fillColor: 'rgba(255, 255, 255, 0)',
|
||||
strokeColor: colors[i],
|
||||
pointColor: colors[i],
|
||||
pointStrokeColor: "#fff",
|
||||
data: times
|
||||
};
|
||||
})
|
||||
}, {
|
||||
bezierCurve: false
|
||||
});
|
||||
|
||||
goButton.disabled = false;
|
||||
goButton.textContent = 'Run Benchmarks';
|
||||
statusSpan.textContent = '';
|
||||
}
|
||||
|
||||
function updateStatus(benchmark, mutationCount, count) {
|
||||
statusSpan.textContent = 'Testing: ' +
|
||||
benchmark.objectCount + ' objects, ' +
|
||||
mutationCount + ' mutations ... ' +
|
||||
count + ' runs';
|
||||
}
|
||||
|
||||
var benchmarks = objectCounts.map(function(objectCount) {
|
||||
return new benchmark(configSelect.value, objectCount);
|
||||
});
|
||||
|
||||
Benchmark.all(benchmarks, mutationCounts, updateStatus)
|
||||
.then(benchmarkComplete);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
357
bower_components/observe-js/benchmark/observation_benchmark.js
vendored
Normal file
357
bower_components/observe-js/benchmark/observation_benchmark.js
vendored
Normal file
@ -0,0 +1,357 @@
|
||||
/*
|
||||
* Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
|
||||
(function(global) {
|
||||
'use strict';
|
||||
|
||||
var createObject = ('__proto__' in {}) ?
|
||||
function(obj) { return obj; } :
|
||||
function(obj) {
|
||||
var proto = obj.__proto__;
|
||||
if (!proto)
|
||||
return obj;
|
||||
var newObject = Object.create(proto);
|
||||
Object.getOwnPropertyNames(obj).forEach(function(name) {
|
||||
Object.defineProperty(newObject, name,
|
||||
Object.getOwnPropertyDescriptor(obj, name));
|
||||
});
|
||||
return newObject;
|
||||
};
|
||||
|
||||
function ObservationBenchmark(objectCount) {
|
||||
Benchmark.call(this);
|
||||
this.objectCount = objectCount;
|
||||
}
|
||||
|
||||
ObservationBenchmark.prototype = createObject({
|
||||
__proto__: Benchmark.prototype,
|
||||
|
||||
setup: function() {
|
||||
this.mutations = 0;
|
||||
|
||||
if (this.objects)
|
||||
return;
|
||||
|
||||
this.objects = [];
|
||||
this.observers = [];
|
||||
this.objectIndex = 0;
|
||||
|
||||
while (this.objects.length < this.objectCount) {
|
||||
var obj = this.newObject();
|
||||
this.objects.push(obj);
|
||||
var observer = this.newObserver(obj);
|
||||
observer.open(this.observerCallback, this);
|
||||
this.observers.push(observer);
|
||||
}
|
||||
},
|
||||
|
||||
test: function(mutationCount) {
|
||||
while (mutationCount > 0) {
|
||||
var obj = this.objects[this.objectIndex];
|
||||
mutationCount -= this.mutateObject(obj);
|
||||
this.mutations++;
|
||||
this.objectIndex++;
|
||||
if (this.objectIndex == this.objects.length) {
|
||||
this.objectIndex = 0;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
cleanup: function() {
|
||||
if (this.mutations !== 0)
|
||||
alert('Error: mutationCount == ' + this.mutationCount);
|
||||
|
||||
this.mutations = 0;
|
||||
},
|
||||
|
||||
dispose: function() {
|
||||
this.objects = null;
|
||||
while (this.observers.length) {
|
||||
this.observers.pop().close();
|
||||
}
|
||||
this.observers = null;
|
||||
if (Observer._allObserversCount != 0) {
|
||||
alert('Observers leaked');
|
||||
}
|
||||
},
|
||||
|
||||
observerCallback: function() {
|
||||
this.mutations--;
|
||||
}
|
||||
});
|
||||
|
||||
function SetupObservationBenchmark(objectCount) {
|
||||
Benchmark.call(this);
|
||||
this.objectCount = objectCount;
|
||||
}
|
||||
|
||||
SetupObservationBenchmark.prototype = createObject({
|
||||
__proto__: Benchmark.prototype,
|
||||
|
||||
setup: function() {
|
||||
this.mutations = 0;
|
||||
this.objects = [];
|
||||
this.observers = [];
|
||||
|
||||
while (this.objects.length < this.objectCount) {
|
||||
var obj = this.newObject();
|
||||
this.objects.push(obj);
|
||||
}
|
||||
},
|
||||
|
||||
test: function() {
|
||||
for (var i = 0; i < this.objects.length; i++) {
|
||||
var obj = this.objects[i];
|
||||
var observer = this.newObserver(obj);
|
||||
observer.open(this.observerCallback, this);
|
||||
this.observers.push(observer);
|
||||
}
|
||||
},
|
||||
|
||||
cleanup: function() {
|
||||
while (this.observers.length) {
|
||||
this.observers.pop().close();
|
||||
}
|
||||
if (Observer._allObserversCount != 0) {
|
||||
alert('Observers leaked');
|
||||
}
|
||||
this.objects = null;
|
||||
this.observers = null;
|
||||
|
||||
},
|
||||
|
||||
dispose: function() {
|
||||
}
|
||||
});
|
||||
|
||||
function ObjectBenchmark(config, objectCount) {
|
||||
ObservationBenchmark.call(this, objectCount);
|
||||
this.properties = [];
|
||||
for (var i = 0; i < ObjectBenchmark.propertyCount; i++) {
|
||||
this.properties.push(String.fromCharCode(97 + i));
|
||||
}
|
||||
}
|
||||
|
||||
ObjectBenchmark.configs = [];
|
||||
ObjectBenchmark.propertyCount = 15;
|
||||
|
||||
ObjectBenchmark.prototype = createObject({
|
||||
__proto__: ObservationBenchmark.prototype,
|
||||
|
||||
newObject: function() {
|
||||
var obj = {};
|
||||
for (var j = 0; j < ObjectBenchmark.propertyCount; j++)
|
||||
obj[this.properties[j]] = j;
|
||||
|
||||
return obj;
|
||||
},
|
||||
|
||||
newObserver: function(obj) {
|
||||
return new ObjectObserver(obj);
|
||||
},
|
||||
|
||||
mutateObject: function(obj) {
|
||||
var size = Math.floor(ObjectBenchmark.propertyCount / 3);
|
||||
for (var i = 0; i < size; i++) {
|
||||
obj[this.properties[i]]++;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
});
|
||||
|
||||
function SetupObjectBenchmark(config, objectCount) {
|
||||
SetupObservationBenchmark.call(this, objectCount);
|
||||
this.properties = [];
|
||||
for (var i = 0; i < ObjectBenchmark.propertyCount; i++) {
|
||||
this.properties.push(String.fromCharCode(97 + i));
|
||||
}
|
||||
}
|
||||
|
||||
SetupObjectBenchmark.configs = [];
|
||||
SetupObjectBenchmark.propertyCount = 15;
|
||||
|
||||
SetupObjectBenchmark.prototype = createObject({
|
||||
__proto__: SetupObservationBenchmark.prototype,
|
||||
|
||||
newObject: function() {
|
||||
var obj = {};
|
||||
for (var j = 0; j < SetupObjectBenchmark.propertyCount; j++)
|
||||
obj[this.properties[j]] = j;
|
||||
|
||||
return obj;
|
||||
},
|
||||
|
||||
newObserver: function(obj) {
|
||||
return new ObjectObserver(obj);
|
||||
}
|
||||
});
|
||||
|
||||
function ArrayBenchmark(config, objectCount) {
|
||||
ObservationBenchmark.call(this, objectCount);
|
||||
var tokens = config.split('/');
|
||||
this.operation = tokens[0];
|
||||
this.undo = tokens[1];
|
||||
};
|
||||
|
||||
ArrayBenchmark.configs = ['splice', 'update', 'push/pop', 'shift/unshift'];
|
||||
ArrayBenchmark.elementCount = 100;
|
||||
|
||||
ArrayBenchmark.prototype = createObject({
|
||||
__proto__: ObservationBenchmark.prototype,
|
||||
|
||||
newObject: function() {
|
||||
var array = [];
|
||||
for (var i = 0; i < ArrayBenchmark.elementCount; i++)
|
||||
array.push(i);
|
||||
return array;
|
||||
},
|
||||
|
||||
newObserver: function(array) {
|
||||
return new ArrayObserver(array);
|
||||
},
|
||||
|
||||
mutateObject: function(array) {
|
||||
switch (this.operation) {
|
||||
case 'update':
|
||||
var mutationsMade = 0;
|
||||
var size = Math.floor(ArrayBenchmark.elementCount / 10);
|
||||
for (var j = 0; j < size; j++) {
|
||||
array[j*size] += 1;
|
||||
mutationsMade++;
|
||||
}
|
||||
return mutationsMade;
|
||||
|
||||
case 'splice':
|
||||
var size = Math.floor(ArrayBenchmark.elementCount / 5);
|
||||
var removed = array.splice(size, size);
|
||||
Array.prototype.splice.apply(array, [size*2, 0].concat(removed));
|
||||
return size * 2;
|
||||
|
||||
default:
|
||||
var val = array[this.undo]();
|
||||
array[this.operation](val + 1);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function SetupArrayBenchmark(config, objectCount) {
|
||||
ObservationBenchmark.call(this, objectCount);
|
||||
};
|
||||
|
||||
SetupArrayBenchmark.configs = [];
|
||||
SetupArrayBenchmark.propertyCount = 15;
|
||||
|
||||
SetupArrayBenchmark.prototype = createObject({
|
||||
__proto__: SetupObservationBenchmark.prototype,
|
||||
|
||||
newObject: function() {
|
||||
var array = [];
|
||||
for (var i = 0; i < ArrayBenchmark.elementCount; i++)
|
||||
array.push(i);
|
||||
return array;
|
||||
},
|
||||
|
||||
newObserver: function(array) {
|
||||
return new ArrayObserver(array);
|
||||
}
|
||||
});
|
||||
|
||||
function PathBenchmark(config, objectCount) {
|
||||
ObservationBenchmark.call(this, objectCount);
|
||||
this.leaf = config === 'leaf';
|
||||
this.path = Path.get('foo.bar.baz');
|
||||
this.firstPathProp = Path.get(this.path[0]);
|
||||
}
|
||||
|
||||
PathBenchmark.configs = ['leaf', 'root'];
|
||||
|
||||
PathBenchmark.prototype = createObject({
|
||||
__proto__: ObservationBenchmark.prototype,
|
||||
|
||||
newPath: function(parts, value) {
|
||||
var obj = {};
|
||||
var ref = obj;
|
||||
var prop;
|
||||
for (var i = 0; i < parts.length - 1; i++) {
|
||||
prop = parts[i];
|
||||
ref[prop] = {};
|
||||
ref = ref[prop];
|
||||
}
|
||||
|
||||
prop = parts[parts.length - 1];
|
||||
ref[prop] = value;
|
||||
|
||||
return obj;
|
||||
},
|
||||
|
||||
newObject: function() {
|
||||
return this.newPath(this.path, 1);
|
||||
},
|
||||
|
||||
newObserver: function(obj) {
|
||||
return new PathObserver(obj, this.path);
|
||||
},
|
||||
|
||||
mutateObject: function(obj) {
|
||||
var val = this.path.getValueFrom(obj);
|
||||
if (this.leaf) {
|
||||
this.path.setValueFrom(obj, val + 1);
|
||||
} else {
|
||||
this.firstPathProp.setValueFrom(obj, this.newPath(this.path.slice(1), val + 1));
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
|
||||
function SetupPathBenchmark(config, objectCount) {
|
||||
ObservationBenchmark.call(this, objectCount);
|
||||
this.path = Path.get('foo.bar.baz');
|
||||
}
|
||||
|
||||
SetupPathBenchmark.configs = [];
|
||||
|
||||
SetupPathBenchmark.prototype = createObject({
|
||||
__proto__: SetupObservationBenchmark.prototype,
|
||||
|
||||
newPath: function(parts, value) {
|
||||
var obj = {};
|
||||
var ref = obj;
|
||||
var prop;
|
||||
for (var i = 0; i < parts.length - 1; i++) {
|
||||
prop = parts[i];
|
||||
ref[prop] = {};
|
||||
ref = ref[prop];
|
||||
}
|
||||
|
||||
prop = parts[parts.length - 1];
|
||||
ref[prop] = value;
|
||||
|
||||
return obj;
|
||||
},
|
||||
|
||||
newObject: function() {
|
||||
return this.newPath(this.path, 1);
|
||||
},
|
||||
|
||||
newObserver: function(obj) {
|
||||
return new PathObserver(obj, this.path);
|
||||
}
|
||||
});
|
||||
|
||||
global.ObjectBenchmark = ObjectBenchmark;
|
||||
global.SetupObjectBenchmark = SetupObjectBenchmark;
|
||||
global.ArrayBenchmark = ArrayBenchmark;
|
||||
global.SetupArrayBenchmark = SetupArrayBenchmark;
|
||||
global.PathBenchmark = PathBenchmark;
|
||||
global.SetupPathBenchmark = SetupPathBenchmark;
|
||||
|
||||
})(this);
|
22
bower_components/observe-js/bower.json
vendored
Normal file
22
bower_components/observe-js/bower.json
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "observe-js",
|
||||
"homepage": "https://github.com/Polymer/observe-js",
|
||||
"authors": [
|
||||
"The Polymer Authors"
|
||||
],
|
||||
"description": "A library for observing Arrays, Objects and PathValues",
|
||||
"main": "src/observe.js",
|
||||
"keywords": [
|
||||
"Object.observe"
|
||||
],
|
||||
"license": "BSD",
|
||||
"private": true,
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"bower_components",
|
||||
"test",
|
||||
"tests"
|
||||
],
|
||||
"version": "0.5.1"
|
||||
}
|
4
bower_components/observe-js/codereview.settings
vendored
Normal file
4
bower_components/observe-js/codereview.settings
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
# This file is used by gcl to get repository specific information.
|
||||
CODE_REVIEW_SERVER: https://codereview.appspot.com
|
||||
VIEW_VC: https://github.com/Polymer/observe-js/commit/
|
||||
|
32
bower_components/observe-js/conf/karma.conf.js
vendored
Normal file
32
bower_components/observe-js/conf/karma.conf.js
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* @license
|
||||
* Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
|
||||
module.exports = function(karma) {
|
||||
var common = require('../../tools/test/karma-common.conf.js');
|
||||
karma.set(common.mixin_common_opts(karma, {
|
||||
// base path, that will be used to resolve files and exclude
|
||||
basePath: '../',
|
||||
|
||||
// list of files / patterns to load in the browser
|
||||
files: [
|
||||
'node_modules/chai/chai.js',
|
||||
'conf/mocha.conf.js',
|
||||
'src/observe.js',
|
||||
'util/array_reduction.js',
|
||||
'tests/*.js'
|
||||
],
|
||||
|
||||
// list of files to exclude
|
||||
exclude: [
|
||||
'tests/d8_array_fuzzer.js',
|
||||
'tests/d8_planner_test.js'
|
||||
],
|
||||
}));
|
||||
};
|
15
bower_components/observe-js/conf/mocha.conf.js
vendored
Normal file
15
bower_components/observe-js/conf/mocha.conf.js
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* @license
|
||||
* Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
|
||||
mocha.setup({
|
||||
ui:'tdd',
|
||||
ignoreLeaks: true
|
||||
});
|
||||
var assert = chai.assert;
|
63
bower_components/observe-js/examples/circles.html
vendored
Normal file
63
bower_components/observe-js/examples/circles.html
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
<!--
|
||||
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
|
||||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
Code distributed by Google as part of the polymer project is also
|
||||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
-->
|
||||
|
||||
<script src="../change_summary.js"></script>
|
||||
<script src="constrain.js"></script>
|
||||
<script src="persist.js"></script>
|
||||
<script src="mdv-object-observe/include.js"></script>
|
||||
|
||||
<h1>Circles</h1>
|
||||
<div data-controller="CircleController">
|
||||
<template iterate>
|
||||
<div style="border: 1px solid black; margin: 8px">
|
||||
<table>
|
||||
<tr><td>radius:</td><td><input type="number" value="{{ radius }}"></td></tr>
|
||||
<tr><td>area:</td><td><input type="number" value="{{ area }}"></td></tr>
|
||||
<tr><td>circumference:</td><td><input type="number" value="{{ circumference }}"></td></tr>
|
||||
</table>
|
||||
<button data-action="click:delete">Delete</button>
|
||||
</div>
|
||||
</template>
|
||||
<button data-action="click:add">New</button>
|
||||
</div>
|
||||
<script>
|
||||
|
||||
function Circle(radius) {
|
||||
// circumference = 2*PI*radius
|
||||
constrain(this, {
|
||||
radius: function() { return this.circumference / (2*Math.PI); },
|
||||
circumference: function() { return 2 * Math.PI * this.radius; }
|
||||
});
|
||||
|
||||
// area = PI*r^2'
|
||||
constrain(this, {
|
||||
area: function() { return Math.PI * Math.pow(this.radius, 2); },
|
||||
radius: function() { return Math.sqrt(this.area / Math.PI); }
|
||||
});
|
||||
|
||||
if (radius)
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
function CircleController(elm) {
|
||||
this.circles = elm.model = persistDB.retrieve(Circle);
|
||||
}
|
||||
|
||||
CircleController.prototype = {
|
||||
delete: function(circle) {
|
||||
var index = this.circles.indexOf(circle);
|
||||
this.circles.splice(index, 1);
|
||||
},
|
||||
|
||||
add: function() {
|
||||
this.circles.push(new Circle());
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
29
bower_components/observe-js/examples/constrain.html
vendored
Normal file
29
bower_components/observe-js/examples/constrain.html
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
<!--
|
||||
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
|
||||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
Code distributed by Google as part of the polymer project is also
|
||||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
-->
|
||||
|
||||
<h1>The world's simplest constraint-solver</h1>
|
||||
<script src="constrain.js"></script>
|
||||
<script>
|
||||
function Circle(radius) {
|
||||
// circumference = 2*PI*radius
|
||||
constrain(this, {
|
||||
radius: function() { return this.circumference / (2*Math.PI); },
|
||||
circumference: function() { return 2 * Math.PI * this.radius; }
|
||||
});
|
||||
|
||||
// area = PI*r^2'
|
||||
constrain(this, {
|
||||
area: function() { return Math.PI * Math.pow(this.radius, 2); },
|
||||
radius: function() { return Math.sqrt(this.area / Math.PI); }
|
||||
});
|
||||
|
||||
if (radius)
|
||||
this.radius = radius;
|
||||
}
|
||||
</script>
|
403
bower_components/observe-js/examples/constrain.js
vendored
Normal file
403
bower_components/observe-js/examples/constrain.js
vendored
Normal file
@ -0,0 +1,403 @@
|
||||
/*
|
||||
* Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
|
||||
(function(global) {
|
||||
|
||||
/* This is a very simple version of the QuickPlan algorithm for solving
|
||||
* mutli-variable contraints. (http://www.cs.utk.edu/~bvz/quickplan.html)
|
||||
* The implementation varies from the standard described approach in a few ways:
|
||||
*
|
||||
* -There is no notion of constraint heirarchy. Here, all constraints are
|
||||
* considered REQUIRED.
|
||||
*
|
||||
* -There is no "improvement" phase where rejected constraints are added back
|
||||
* in an attempt to find a "better solution"
|
||||
*
|
||||
* -In place of the above two, a heuristic is used to pick the "weakest"
|
||||
* free constraint to remove. A function, "stayFunc" is passed to the
|
||||
* Variable class and is expected to return a priority value for the variable
|
||||
* 0 being highest and 1, 2, 3, etc... being lower.
|
||||
*
|
||||
* I suspect these variations result in there being no guarentee of choosing the
|
||||
* optimal solution, but it does seem to work well for the examples I've tested.
|
||||
* Note also that the DeltaBlue planner can be used in a similar pattern,
|
||||
* but it only supports single variable assignment.
|
||||
*
|
||||
* Note also that this is hacky and thrown together. Don't expect it to work
|
||||
* much at all =-).
|
||||
*/
|
||||
|
||||
function Map() {
|
||||
this.map_ = new global.Map;
|
||||
this.keys_ = [];
|
||||
}
|
||||
|
||||
Map.prototype = {
|
||||
get: function(key) {
|
||||
return this.map_.get(key);
|
||||
},
|
||||
|
||||
set: function(key, value) {
|
||||
if (!this.map_.has(key))
|
||||
this.keys_.push(key);
|
||||
return this.map_.set(key, value);
|
||||
},
|
||||
|
||||
has: function(key) {
|
||||
return this.map_.has(key);
|
||||
},
|
||||
|
||||
delete: function(key) {
|
||||
this.keys_.splice(this.keys_.indexOf(key), 1);
|
||||
this.map_.delete(key);
|
||||
},
|
||||
|
||||
keys: function() {
|
||||
return this.keys_.slice();
|
||||
}
|
||||
}
|
||||
|
||||
function Variable(property, stayFunc) {
|
||||
this.property = property;
|
||||
this.stayFunc = stayFunc || function() {
|
||||
//console.log("Warning: using default stay func");
|
||||
return 0;
|
||||
};
|
||||
this.methods = [];
|
||||
};
|
||||
|
||||
Variable.prototype = {
|
||||
addMethod: function(method) {
|
||||
this.methods.push(method);
|
||||
},
|
||||
|
||||
removeMethod: function(method) {
|
||||
this.methods.splice(this.methods.indexOf(method), 1);
|
||||
},
|
||||
|
||||
isFree: function() {
|
||||
return this.methods.length <= 1;
|
||||
},
|
||||
|
||||
get stayPriority() {
|
||||
return this.stayFunc(this.property);
|
||||
}
|
||||
}
|
||||
|
||||
function Method(opts) {
|
||||
opts = opts || {};
|
||||
this.name = opts.name || 'function() { ... }';
|
||||
this.outputs = opts.outputs || [];
|
||||
this.f = opts.f || function() {
|
||||
console.log('Warning: using default execution function');
|
||||
};
|
||||
};
|
||||
|
||||
Method.prototype = {
|
||||
planned_: false,
|
||||
variables_: [],
|
||||
|
||||
set planned(planned) {
|
||||
this.planned_ = planned;
|
||||
|
||||
if (this.planned_) {
|
||||
if (this.variables_) {
|
||||
// Remove this method from all variables.
|
||||
this.variables_.forEach(function(variable) {
|
||||
variable.removeMethod(this);
|
||||
}, this);
|
||||
}
|
||||
|
||||
this.variables_ = null;
|
||||
} else {
|
||||
this.variables_ = null;
|
||||
|
||||
// Get & add this method to all variables.
|
||||
if (this.constraint && this.constraint.planner) {
|
||||
this.variables_ = this.outputs.map(function(output) {
|
||||
var variable = this.constraint.planner.getVariable(output);
|
||||
variable.addMethod(this);
|
||||
return variable;
|
||||
}, this);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
get planned() {
|
||||
return this.planned_;
|
||||
},
|
||||
|
||||
isFree: function() {
|
||||
// Return true only if all variables are free.
|
||||
var variables = this.variables_;
|
||||
for (var i = variables.length - 1; i >= 0; i--) {
|
||||
if (!variables[i].isFree())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
weakerOf: function(other) {
|
||||
if (!other) {
|
||||
return this;
|
||||
}
|
||||
|
||||
// Prefer a method that assigns to fewer variables.
|
||||
if (this.variables_.length != other.variables_.length) {
|
||||
return this.variables_.length < other.variables_.length ? this : other;
|
||||
}
|
||||
|
||||
// Note: A weaker stay priority is a higher number.
|
||||
return this.getStayPriority() >= other.getStayPriority() ? this : other;
|
||||
},
|
||||
|
||||
getStayPriority: function() {
|
||||
// This returns the strongest (lowest) stay priority of this method's
|
||||
// output variables.
|
||||
return retval = this.variables_.reduce(function(min, variable) {
|
||||
return Math.min(min, variable.stayPriority);
|
||||
}, Infinity);
|
||||
},
|
||||
|
||||
execute: function() {
|
||||
console.log(JSON.stringify(this.outputs) + ' <= ' + this.name);
|
||||
this.f();
|
||||
}
|
||||
};
|
||||
|
||||
function Constraint(methods, when) {
|
||||
this.methods = methods;
|
||||
this.when = when;
|
||||
};
|
||||
|
||||
Constraint.prototype = {
|
||||
executionMethod_: null,
|
||||
|
||||
set executionMethod(executionMethod) {
|
||||
this.executionMethod_ = executionMethod;
|
||||
var planned = !!this.executionMethod_;
|
||||
|
||||
this.methods.forEach(function(method) {
|
||||
method.constraint = this;
|
||||
method.planned = planned;
|
||||
}, this);
|
||||
},
|
||||
|
||||
get executionMethod() {
|
||||
return this.executionMethod_;
|
||||
},
|
||||
|
||||
getWeakestFreeMethod: function() {
|
||||
var methods = this.methods;
|
||||
var weakest = null;
|
||||
for (var i = 0; i < methods.length; i++) {
|
||||
var method = methods[i];
|
||||
if (method.isFree())
|
||||
weakest = method.weakerOf(weakest);
|
||||
}
|
||||
return weakest;
|
||||
},
|
||||
|
||||
execute: function() {
|
||||
this.executionMethod.execute();
|
||||
}
|
||||
};
|
||||
|
||||
function Planner(object) {
|
||||
this.object = object;
|
||||
this.properties = {};
|
||||
this.priority = []
|
||||
var self = this;
|
||||
|
||||
this.stayFunc = function(property) {
|
||||
if (self.object[property] === undefined)
|
||||
return Infinity;
|
||||
var index = self.priority.indexOf(property);
|
||||
return index >= 0 ? index : Infinity;
|
||||
}
|
||||
|
||||
Object.observe(this.object, internalCallback);
|
||||
};
|
||||
|
||||
Planner.prototype = {
|
||||
plan_: null,
|
||||
|
||||
deliverChanged: function(changeRecords) {
|
||||
var needsResolve = false;
|
||||
|
||||
changeRecords.forEach(function(change) {
|
||||
var property = change.name;
|
||||
if (!(property in this.properties))
|
||||
return;
|
||||
|
||||
var index = this.priority.indexOf(property);
|
||||
if (index >= 0)
|
||||
this.priority.splice(this.priority.indexOf(property), 1);
|
||||
|
||||
this.priority.unshift(property);
|
||||
needsResolve = true;
|
||||
}, this);
|
||||
|
||||
if (!needsResolve)
|
||||
return;
|
||||
|
||||
console.log('Resolving: ' + Object.getPrototypeOf(changeRecords[0].object).constructor.name);
|
||||
|
||||
Object.unobserve(this.object, internalCallback);
|
||||
this.execute();
|
||||
console.log('...Done: ' + JSON.stringify(this.object));
|
||||
Object.observe(this.object, internalCallback);
|
||||
},
|
||||
|
||||
addConstraint: function(methods) {
|
||||
methods.forEach(function(method) {
|
||||
method.outputs.forEach(function(output) {
|
||||
this.properties[output] = true;
|
||||
}, this);
|
||||
}, this);
|
||||
|
||||
var constraint = new Constraint(methods);
|
||||
|
||||
this.constraints = this.constraints || [];
|
||||
if (this.constraints.indexOf(constraint) < 0) {
|
||||
this.plan_ = null;
|
||||
this.constraints.push(constraint);
|
||||
}
|
||||
return constraint;
|
||||
},
|
||||
|
||||
removeConstraint: function(constraint) {
|
||||
var index = this.constraints.indexOf(constraint);
|
||||
if (index >= 0) {
|
||||
this.plan_ = null;
|
||||
var removed = this.constraints.splice(index, 1)[0];
|
||||
}
|
||||
return constraint;
|
||||
},
|
||||
|
||||
getVariable: function(property) {
|
||||
var index = this.properties_.indexOf(property);
|
||||
if (index >= 0) {
|
||||
return this.variables_[index];
|
||||
}
|
||||
|
||||
this.properties_.push(property);
|
||||
var variable = new Variable(property, this.stayFunc);
|
||||
this.variables_.push(variable);
|
||||
return variable;
|
||||
},
|
||||
|
||||
get plan() {
|
||||
if (this.plan_) {
|
||||
return this.plan_;
|
||||
}
|
||||
|
||||
this.plan_ = [];
|
||||
this.properties_ = [];
|
||||
this.variables_ = [];
|
||||
|
||||
var unplanned = this.constraints.filter(function(constraint) {
|
||||
// Note: setting executionMethod must take place after setting planner.
|
||||
if (constraint.when && !constraint.when()) {
|
||||
// Conditional and currenty disabled => not in use.
|
||||
constraint.planner = null;
|
||||
constraint.executionMethod = null;
|
||||
return false;
|
||||
} else {
|
||||
// In use.
|
||||
constraint.planner = this;
|
||||
constraint.executionMethod = null;
|
||||
return true;
|
||||
}
|
||||
}, this);
|
||||
|
||||
while (unplanned.length > 0) {
|
||||
var method = this.chooseNextMethod(unplanned);
|
||||
if (!method) {
|
||||
throw "Cycle detected";
|
||||
}
|
||||
|
||||
var nextConstraint = method.constraint;
|
||||
unplanned.splice(unplanned.indexOf(nextConstraint), 1);
|
||||
this.plan_.unshift(nextConstraint);
|
||||
nextConstraint.executionMethod = method;
|
||||
}
|
||||
|
||||
return this.plan_;
|
||||
},
|
||||
|
||||
chooseNextMethod: function(constraints) {
|
||||
var weakest = null;
|
||||
for (var i = 0; i < constraints.length; i++) {
|
||||
var current = constraints[i].getWeakestFreeMethod();
|
||||
weakest = current ? current.weakerOf(weakest) : weakest;
|
||||
}
|
||||
return weakest;
|
||||
},
|
||||
|
||||
run: function() {
|
||||
this.execute();
|
||||
},
|
||||
|
||||
execute: function() {
|
||||
this.plan_ = null;
|
||||
this.executing = true;
|
||||
this.plan.forEach(function(constraint) {
|
||||
constraint.execute();
|
||||
});
|
||||
this.executing = false;
|
||||
}
|
||||
}
|
||||
|
||||
var planners = new WeakMap;
|
||||
|
||||
function internalCallback(changeRecords) {
|
||||
var changeMap = new Map;
|
||||
|
||||
changeRecords.forEach(function(change) {
|
||||
if (!planners.has(change.object))
|
||||
return;
|
||||
|
||||
var changes = changeMap.get(change.object);
|
||||
if (!changes) {
|
||||
changeMap.set(change.object, [change]);
|
||||
return;
|
||||
}
|
||||
|
||||
changes.push(change);
|
||||
});
|
||||
|
||||
changeMap.keys().forEach(function(object) {
|
||||
planners.get(object).deliverChanged(changeMap.get(object));
|
||||
});
|
||||
}
|
||||
|
||||
// Register callback to assign delivery order.
|
||||
var register = {};
|
||||
Object.observe(register, internalCallback);
|
||||
Object.unobserve(register, internalCallback);
|
||||
|
||||
global.constrain = function(obj, methodFunctions) {
|
||||
var planner = planners.get(obj);
|
||||
if (!planner) {
|
||||
planner = new Planner(obj);
|
||||
planners.set(obj, planner);
|
||||
}
|
||||
|
||||
planner.addConstraint(Object.keys(methodFunctions).map(function(property) {
|
||||
var func = methodFunctions[property];
|
||||
|
||||
return new Method({
|
||||
name: func.toString(),
|
||||
outputs: [ property ],
|
||||
f: function() { obj[property] = func.apply(obj); }
|
||||
});
|
||||
}));
|
||||
}
|
||||
})(this);
|
13
bower_components/observe-js/examples/persist.html
vendored
Normal file
13
bower_components/observe-js/examples/persist.html
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
<!--
|
||||
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
|
||||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
Code distributed by Google as part of the polymer project is also
|
||||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
-->
|
||||
|
||||
<h1>The worlds simplest persistence system</h1>
|
||||
|
||||
<script src="../change_summary.js"></script>
|
||||
<script src="persist.js"></script>
|
246
bower_components/observe-js/examples/persist.js
vendored
Normal file
246
bower_components/observe-js/examples/persist.js
vendored
Normal file
@ -0,0 +1,246 @@
|
||||
/*
|
||||
* Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
|
||||
(function(global) {
|
||||
|
||||
function Set() {
|
||||
this.set_ = new global.Set;
|
||||
this.keys_ = [];
|
||||
}
|
||||
|
||||
Set.prototype = {
|
||||
add: function(key) {
|
||||
if (!this.set_.has(key))
|
||||
this.keys_.push(key);
|
||||
return this.set_.add(key);
|
||||
},
|
||||
|
||||
has: function(key) {
|
||||
return this.set_.has(key);
|
||||
},
|
||||
|
||||
delete: function(key) {
|
||||
this.keys_.splice(this.keys_.indexOf(key), 1);
|
||||
this.set_.delete(key);
|
||||
},
|
||||
|
||||
keys: function() {
|
||||
return this.keys_.slice();
|
||||
}
|
||||
}
|
||||
|
||||
var dbName = 'PersistObserved';
|
||||
var version;
|
||||
var db;
|
||||
var storeNames = {};
|
||||
|
||||
function constructorName(objOrFunction) {
|
||||
if (typeof objOrFunction == 'function')
|
||||
return objOrFunction.name;
|
||||
else
|
||||
return Object.getPrototypeOf(objOrFunction).constructor.name;
|
||||
}
|
||||
|
||||
function getKeyPath(constructor) {
|
||||
return constructor.keyPath || 'id';
|
||||
}
|
||||
|
||||
function onerror(e) {
|
||||
console.log('Error: ' + e);
|
||||
};
|
||||
|
||||
var postOpen = [];
|
||||
|
||||
function openDB() {
|
||||
var request = webkitIndexedDB.open(dbName);
|
||||
|
||||
request.onerror = onerror;
|
||||
request.onsuccess = function(e) {
|
||||
db = e.target.result;
|
||||
version = db.version || 0;
|
||||
for (var i = 0; i < db.objectStoreNames.length; i++)
|
||||
storeNames[db.objectStoreNames.item(i)] = true;
|
||||
|
||||
postOpen.forEach(function(action) {
|
||||
action();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function handleChanged(changeRecords) {
|
||||
changeRecords.forEach(function(change) {
|
||||
persist(change.object);
|
||||
});
|
||||
}
|
||||
|
||||
var observer = new ChangeSummary(function(summaries) {
|
||||
storeChanges = {};
|
||||
|
||||
function getChange(obj) {
|
||||
var change = storeChanges[constructorName(obj)];
|
||||
if (change)
|
||||
return change;
|
||||
|
||||
change = {
|
||||
keyPath: getKeyPath(obj),
|
||||
needsAdd: new Set,
|
||||
needsSave: new Set,
|
||||
needsDelete: new Set
|
||||
};
|
||||
|
||||
storeChanges[storeName] = change;
|
||||
return change;
|
||||
}
|
||||
|
||||
summaries.forEach(function(summary) {
|
||||
if (!Array.isArray(summary.object)) {
|
||||
getChange(summary.object).needsSave.add(summary.object);
|
||||
return;
|
||||
}
|
||||
|
||||
summary.arraySplices.forEach(function(splice) {
|
||||
for (var i = 0; i < splice.removed.length; i++) {
|
||||
var obj = splice.removed[i];
|
||||
var change = getChange(obj);
|
||||
if (change.needsAdd.has(obj))
|
||||
change.needsAdd.delete(obj);
|
||||
else
|
||||
change.needsDelete.add(obj);
|
||||
}
|
||||
|
||||
for (var i = splice.index; i < splice.index + splice.addedCount; i++) {
|
||||
var obj = summary.object[i];
|
||||
var change = getChange(obj);
|
||||
if (change.needsDelete.has(obj))
|
||||
change.needsDelete.delete(obj);
|
||||
else
|
||||
change.needsAdd.add(obj);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var storeNames = Object.keys(storeChanges);
|
||||
|
||||
console.log('Persisting: ' + JSON.stringify(storeNames));
|
||||
var trans = db.transaction(storeNames, "readwrite");
|
||||
trans.onerror = onerror;
|
||||
trans.oncomplete = function() {
|
||||
console.log('...complete');
|
||||
}
|
||||
storeNames.forEach(function(storeName) {
|
||||
|
||||
var change = storeChanges[storeName];
|
||||
var store = trans.objectStore(storeName);
|
||||
|
||||
change.needsDelete.keys().forEach(function(obj) {
|
||||
var request = store.delete(obj[change.keyPath]);
|
||||
request.onerror = onerror;
|
||||
request.onsuccess = function(e) {
|
||||
console.log(' deleted: ' + JSON.stringify(obj));
|
||||
delete obj[keyPath];
|
||||
observer.unobserve(obj);
|
||||
if (change.needsSave.has(obj))
|
||||
change.needsSave.delete(obj);
|
||||
};
|
||||
});
|
||||
|
||||
change.needsSave.keys().forEach(function(obj) {
|
||||
var request = store.put(obj);
|
||||
request.onerror = onerror;
|
||||
request.onsuccess = function(e) {
|
||||
console.log(' saved: ' + JSON.stringify(obj));
|
||||
};
|
||||
});
|
||||
|
||||
change.needsAdd.keys().forEach(function(obj) {
|
||||
obj[keyPath] = ++maxIds[storeName];
|
||||
var request = store.put(obj);
|
||||
request.onerror = onerror;
|
||||
request.onsuccess = function(e) {
|
||||
console.log(' created: ' + JSON.stringify(obj));
|
||||
observer.observe(obj);
|
||||
};
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
var maxIds = {};
|
||||
|
||||
global.persistDB = {};
|
||||
|
||||
global.persistDB.retrieve = function(constructor) {
|
||||
var results = [];
|
||||
var instance = new constructor();
|
||||
|
||||
keyPath = constructor.keyPath || 'id';
|
||||
storeName = constructor.name;
|
||||
maxIds[storeName] = maxIds[storeName] || 0;
|
||||
|
||||
function doRetrieve() {
|
||||
console.log("Retrieving: " + storeName);
|
||||
|
||||
var trans = db.transaction([storeName]);
|
||||
var store = trans.objectStore(storeName);
|
||||
|
||||
var keyRange = webkitIDBKeyRange.lowerBound(0);
|
||||
var request = store.openCursor(keyRange);
|
||||
|
||||
request.onerror = onerror;
|
||||
|
||||
request.onsuccess = function(e) {
|
||||
var result = e.target.result;
|
||||
if (!!result == false) {
|
||||
observer.observePropertySet(results);
|
||||
console.log('...complete');
|
||||
return;
|
||||
}
|
||||
|
||||
var object = result.value;
|
||||
maxIds[storeName] = Math.max(maxIds[storeName], object[keyPath]);
|
||||
|
||||
object.__proto__ = instance;
|
||||
constructor.apply(object);
|
||||
results.push(object);
|
||||
observer.observe(object);
|
||||
|
||||
console.log(' => ' + JSON.stringify(object));
|
||||
result.continue();
|
||||
};
|
||||
}
|
||||
|
||||
function createStore() {
|
||||
console.log('Creating store: ' + storeName);
|
||||
version++;
|
||||
var request = db.setVersion(version);
|
||||
request.onerror = onerror;
|
||||
|
||||
request.onsuccess = function(e) {
|
||||
var store = db.createObjectStore(storeName, { keyPath: keyPath });
|
||||
storeNames[storeName] = true;
|
||||
e.target.transaction.oncomplete = doRetrieve;
|
||||
};
|
||||
}
|
||||
|
||||
var action = function() {
|
||||
if (storeName in storeNames)
|
||||
doRetrieve()
|
||||
else
|
||||
createStore();
|
||||
}
|
||||
|
||||
if (db)
|
||||
action();
|
||||
else
|
||||
postOpen.push(action);
|
||||
|
||||
return results;
|
||||
};
|
||||
|
||||
openDB();
|
||||
})(this);
|
32
bower_components/observe-js/gruntfile.js
vendored
Normal file
32
bower_components/observe-js/gruntfile.js
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
|
||||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
* Code distributed by Google as part of the polymer project is also
|
||||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
*/
|
||||
|
||||
module.exports = function(grunt) {
|
||||
grunt.initConfig({
|
||||
karma: {
|
||||
options: {
|
||||
configFile: 'conf/karma.conf.js',
|
||||
keepalive: true
|
||||
},
|
||||
buildbot: {
|
||||
reporters: ['crbot'],
|
||||
logLevel: 'OFF'
|
||||
},
|
||||
'observe-js': {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
grunt.loadTasks('../tools/tasks');
|
||||
grunt.loadNpmTasks('grunt-karma');
|
||||
|
||||
grunt.registerTask('default', 'test');
|
||||
grunt.registerTask('test', ['override-chrome-launcher', 'karma:observe-js']);
|
||||
grunt.registerTask('test-buildbot', ['override-chrome-launcher', 'karma:buildbot']);
|
||||
};
|
73
bower_components/observe-js/index.html
vendored
Normal file
73
bower_components/observe-js/index.html
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
<!--
|
||||
@license
|
||||
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
|
||||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
Code distributed by Google as part of the polymer project is also
|
||||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
-->
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>polymer api</title>
|
||||
<style>
|
||||
html, body {
|
||||
font-family: Arial, sans-serif;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
}
|
||||
[noviewer] [ifnoviewer] {
|
||||
display: block;
|
||||
}
|
||||
[detector], [ifnoviewer], [noviewer] [ifviewer] {
|
||||
display: none;
|
||||
}
|
||||
[ifviewer], [ifnoviewer] {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
}
|
||||
iframe {
|
||||
border: none;
|
||||
margin: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
#remote {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
}
|
||||
</style>
|
||||
<script src="../webcomponentsjs/webcomponents.js"></script>
|
||||
<link rel="import" href="../polymer-home-page/polymer-home-page.html">
|
||||
</head>
|
||||
<body>
|
||||
<img detector src="../polymer-home-page/bowager-logo.png" onerror="noviewer()">
|
||||
<polymer-home-page ifviewer></polymer-home-page>
|
||||
<div ifnoviewer>
|
||||
<span id="remote">[remote]</span>
|
||||
<iframe></iframe>
|
||||
</div>
|
||||
<!-- -->
|
||||
<script>
|
||||
var remoteDocs = 'http://turbogadgetry.com/bowertopia/components/';
|
||||
// if no local info viewer, load it remotely
|
||||
function noviewer() {
|
||||
document.body.setAttribute('noviewer', '');
|
||||
var path = location.pathname.split('/');
|
||||
var module = path.pop() || path.pop();
|
||||
document.querySelector('iframe').src = remoteDocs + module;
|
||||
document.querySelector('title').textContent = module;
|
||||
}
|
||||
// for testing only
|
||||
var opts = window.location.search;
|
||||
if (opts.indexOf('noviewer') >= 0) {
|
||||
noviewer();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
33
bower_components/observe-js/package.json
vendored
Normal file
33
bower_components/observe-js/package.json
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "observe-js",
|
||||
"version": "0.4.2",
|
||||
"description": "observe-js is a library for observing changes on JavaScript objects/arrays",
|
||||
"main": "src/observe.js",
|
||||
"directories": {
|
||||
"example": "examples",
|
||||
"test": "tests"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Polymer/observe-js.git"
|
||||
},
|
||||
"author": "The Polymer Authors",
|
||||
"license": "BSD",
|
||||
"readmeFilename": "README.md",
|
||||
"devDependencies": {
|
||||
"chai": "*",
|
||||
"mocha": "*",
|
||||
"grunt": "*",
|
||||
"grunt-karma": "*",
|
||||
"karma": "~0.12.0",
|
||||
"karma-mocha": "*",
|
||||
"karma-firefox-launcher": "*",
|
||||
"karma-ie-launcher": "*",
|
||||
"karma-safari-launcher": "*",
|
||||
"karma-script-launcher": "*",
|
||||
"karma-crbot-reporter": "*"
|
||||
}
|
||||
}
|
1711
bower_components/observe-js/src/observe.js
vendored
Normal file
1711
bower_components/observe-js/src/observe.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
309
bower_components/observe-js/util/planner.js
vendored
Normal file
309
bower_components/observe-js/util/planner.js
vendored
Normal file
@ -0,0 +1,309 @@
|
||||
// Copyright 2012 Google Inc.
|
||||
//
|
||||
// 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.
|
||||
|
||||
(function(global) {
|
||||
|
||||
"use strict";
|
||||
|
||||
function ArraySet() {
|
||||
this.entries = [];
|
||||
}
|
||||
|
||||
ArraySet.prototype = {
|
||||
add: function(key) {
|
||||
if (this.entries.indexOf(key) >= 0)
|
||||
return;
|
||||
|
||||
this.entries.push(key);
|
||||
},
|
||||
|
||||
delete: function(key) {
|
||||
var i = this.entries.indexOf(key);
|
||||
if (i < 0)
|
||||
return;
|
||||
|
||||
this.entries.splice(i, 1);
|
||||
},
|
||||
|
||||
first: function() {
|
||||
return this.entries[0];
|
||||
},
|
||||
|
||||
get size() {
|
||||
return this.entries.length;
|
||||
}
|
||||
};
|
||||
|
||||
function UIDSet() {
|
||||
this.entries = {};
|
||||
this.size = 0;
|
||||
}
|
||||
|
||||
UIDSet.prototype = {
|
||||
add: function(key) {
|
||||
if (this.entries[key.__UID__] !== undefined)
|
||||
return;
|
||||
|
||||
this.entries[key.__UID__] = key;
|
||||
this.size++;
|
||||
},
|
||||
|
||||
delete: function(key) {
|
||||
if (this.entries[key.__UID__] === undefined)
|
||||
return;
|
||||
|
||||
this.entries[key.__UID__] = undefined;
|
||||
this.size--;
|
||||
}
|
||||
};
|
||||
|
||||
function Heap(scoreFunction, populate) {
|
||||
this.scoreFunction = scoreFunction;
|
||||
this.content = populate || [];
|
||||
if (this.content.length)
|
||||
this.build();
|
||||
}
|
||||
|
||||
Heap.prototype = {
|
||||
get size() {
|
||||
return this.content.length;
|
||||
},
|
||||
|
||||
build: function() {
|
||||
var lastNonLeaf = Math.floor(this.content.length / 2) - 1;
|
||||
for (var i = lastNonLeaf; i >= 0; i--)
|
||||
this.sinkDown(i);
|
||||
},
|
||||
|
||||
push: function(element) {
|
||||
this.content.push(element);
|
||||
this.bubbleUp(this.content.length - 1);
|
||||
},
|
||||
|
||||
pop: function() {
|
||||
var result = this.content[0];
|
||||
var end = this.content.pop();
|
||||
if (this.content.length) {
|
||||
this.content[0] = end;
|
||||
this.sinkDown(0);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
delete: function(element) {
|
||||
var len = this.content.length;
|
||||
for (var i = 0; i < len; i++) {
|
||||
if (this.content[i] == element) {
|
||||
var end = this.content.pop();
|
||||
if (i != len - 1) {
|
||||
this.content[i] = end;
|
||||
if (this.scoreFunction(end) < this.scoreFunction(node)) this.bubbleUp(i);
|
||||
else this.sinkDown(i);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
bubbleUp: function(n) {
|
||||
var element = this.content[n];
|
||||
while (n > 0) {
|
||||
var parentN = Math.floor((n + 1) / 2) - 1,
|
||||
parent = this.content[parentN];
|
||||
|
||||
if (this.scoreFunction(element) <= this.scoreFunction(parent))
|
||||
break;
|
||||
|
||||
this.content[parentN] = element;
|
||||
this.content[n] = parent;
|
||||
n = parentN;
|
||||
}
|
||||
},
|
||||
|
||||
sinkDown: function(n) {
|
||||
var length = this.content.length,
|
||||
element = this.content[n],
|
||||
elemScore = this.scoreFunction(element);
|
||||
|
||||
do {
|
||||
var child2N = (n + 1) * 2
|
||||
var child1N = child2N - 1;
|
||||
|
||||
var swap = null;
|
||||
var swapScore = elemScore;
|
||||
|
||||
if (child1N < length) {
|
||||
var child1 = this.content[child1N],
|
||||
child1Score = this.scoreFunction(child1);
|
||||
if (child1Score > elemScore) {
|
||||
swap = child1N;
|
||||
swapScore = child1Score;
|
||||
}
|
||||
}
|
||||
|
||||
if (child2N < length) {
|
||||
var child2 = this.content[child2N],
|
||||
child2Score = this.scoreFunction(child2);
|
||||
if (child2Score > swapScore)
|
||||
swap = child2N;
|
||||
}
|
||||
|
||||
if (swap != null) {
|
||||
this.content[n] = this.content[swap];
|
||||
this.content[swap] = element;
|
||||
n = swap;
|
||||
}
|
||||
} while (swap != null);
|
||||
}
|
||||
};
|
||||
|
||||
function Variable(stayFunc) {
|
||||
this.stayFunc = stayFunc;
|
||||
this.methods = new ArraySet;
|
||||
};
|
||||
|
||||
Variable.prototype = {
|
||||
freeMethod: function() {
|
||||
return this.methods.first();
|
||||
}
|
||||
}
|
||||
|
||||
function Method(constraint, variable) {
|
||||
this.constraint = constraint;
|
||||
this.variable = variable;
|
||||
};
|
||||
|
||||
function Constraint(planner) {
|
||||
this.planner = planner;
|
||||
this.methods = [];
|
||||
};
|
||||
|
||||
Constraint.prototype = {
|
||||
addMethod: function(variable) {
|
||||
var method = new Method(this, variable);
|
||||
this.methods.push(method);
|
||||
method.__UID__ = this.planner.methodUIDCounter++;
|
||||
return method;
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
this.methods.forEach(function(method) {
|
||||
method.variable.methods.add(method);
|
||||
});
|
||||
},
|
||||
|
||||
remove: function() {
|
||||
this.methods.forEach(function(method) {
|
||||
method.variable.methods.delete(method);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function Planner() {
|
||||
this.variables = [];
|
||||
this.constraints = [];
|
||||
this.variableUIDCounter = 1;
|
||||
this.methodUIDCounter = 1;
|
||||
};
|
||||
|
||||
Planner.prototype = {
|
||||
addVariable: function(stayFunc) {
|
||||
var variable = new Variable(stayFunc);
|
||||
variable.__UID__ = this.variableUIDCounter++;
|
||||
this.variables.push(variable);
|
||||
return variable;
|
||||
},
|
||||
|
||||
addConstraint: function() {
|
||||
var constraint = new Constraint(this);
|
||||
this.constraints.push(constraint);
|
||||
return constraint;
|
||||
},
|
||||
|
||||
removeConstraint: function(constraint) {
|
||||
var index = this.constraints.indexOf(constraint);
|
||||
if (index < 0)
|
||||
return;
|
||||
|
||||
constraint.remove();
|
||||
this.constraints.splice(index, 1);
|
||||
|
||||
this.constraints.forEach(function(constraint) {
|
||||
constraint.reset();
|
||||
});
|
||||
|
||||
this.variables = this.variables.filter(function(variable) {
|
||||
return variable.methods.size;
|
||||
});
|
||||
},
|
||||
|
||||
getPlan: function() {
|
||||
this.variables.forEach(function(variable) {
|
||||
variable.priority = variable.stayFunc();
|
||||
});
|
||||
|
||||
this.constraints.forEach(function(constraint) {
|
||||
constraint.reset();
|
||||
});
|
||||
|
||||
var methods = [];
|
||||
var free = [];
|
||||
var overconstrained = new UIDSet;
|
||||
|
||||
this.variables.forEach(function(variable) {
|
||||
var methodCount = variable.methods.size;
|
||||
|
||||
if (methodCount > 1)
|
||||
overconstrained.add(variable);
|
||||
else if (methodCount == 1)
|
||||
free.push(variable);
|
||||
});
|
||||
|
||||
free = new Heap(function(variable) {
|
||||
return variable.priority;
|
||||
}, free);
|
||||
|
||||
while (free.size) {
|
||||
var lowest;
|
||||
do {
|
||||
lowest = free.pop();
|
||||
} while (free.size && !lowest.methods.size);
|
||||
|
||||
if (!lowest.methods.size)
|
||||
break;
|
||||
|
||||
var method = lowest.freeMethod();
|
||||
var constraint = method.constraint;
|
||||
|
||||
constraint.remove();
|
||||
constraint.methods.forEach(function(method) {
|
||||
var variable = method.variable;
|
||||
if (variable.methods.size == 1) {
|
||||
overconstrained.delete(variable);
|
||||
free.push(variable);
|
||||
}
|
||||
});
|
||||
|
||||
methods.push(method);
|
||||
}
|
||||
|
||||
if (overconstrained.size)
|
||||
return undefined;
|
||||
|
||||
return methods.reverse();
|
||||
}
|
||||
}
|
||||
|
||||
global.Planner = Planner;
|
||||
})(this);
|
21
bower_components/observe-shim/.bower.json
vendored
Normal file
21
bower_components/observe-shim/.bower.json
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "observe-shim",
|
||||
"version": "0.4.2",
|
||||
"main": "lib/observe-shim.js",
|
||||
"devDependencies": {
|
||||
"mocha": "~1.8.x",
|
||||
"expect": "~0.2.0",
|
||||
"sinon": "http://sinonjs.org/releases/sinon-1.6.0.js"
|
||||
},
|
||||
"homepage": "https://github.com/KapIT/observe-shim",
|
||||
"_release": "0.4.2",
|
||||
"_resolution": {
|
||||
"type": "version",
|
||||
"tag": "v0.4.2",
|
||||
"commit": "75e8ea887c38bd1540fe4989a17b6e3751d7c7e5"
|
||||
},
|
||||
"_source": "git://github.com/KapIT/observe-shim.git",
|
||||
"_target": "~0.4.2",
|
||||
"_originalSource": "observe-shim",
|
||||
"_direct": true
|
||||
}
|
3
bower_components/observe-shim/.bowerrc
vendored
Normal file
3
bower_components/observe-shim/.bowerrc
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"directory": "components"
|
||||
}
|
5
bower_components/observe-shim/.gitignore
vendored
Normal file
5
bower_components/observe-shim/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
node_modules
|
||||
npm-debug.log
|
||||
.DS_Store
|
||||
.idea
|
||||
components
|
21
bower_components/observe-shim/.jshintrc
vendored
Normal file
21
bower_components/observe-shim/.jshintrc
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"bitwise": false,
|
||||
"camelcase" : true,
|
||||
"curly" : true,
|
||||
"immed" : true,
|
||||
"indent": 4,
|
||||
"latedef" : true,
|
||||
"newcap" : true,
|
||||
"noarg" : true,
|
||||
"undef" : true,
|
||||
"unused" : true,
|
||||
"strict" : true,
|
||||
"trailing": true,
|
||||
"node": true,
|
||||
"es5": true,
|
||||
"esnext": true,
|
||||
"regexp": true,
|
||||
"smarttabs": true,
|
||||
"eqeqeq" : true,
|
||||
"quotmark" : "single"
|
||||
}
|
55
bower_components/observe-shim/Gruntfile.js
vendored
Normal file
55
bower_components/observe-shim/Gruntfile.js
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
// 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,
|
||||
log : true
|
||||
}
|
||||
},
|
||||
mochaTest : {
|
||||
test: {
|
||||
options: {
|
||||
reporter: 'spec'
|
||||
},
|
||||
src: ['test/node-index.js']
|
||||
}
|
||||
},
|
||||
clean : {
|
||||
folder : ['docs']
|
||||
},
|
||||
docco: {
|
||||
src: ['lib/observe-shim.js'],
|
||||
options: {
|
||||
output: 'docs/'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
grunt.registerTask('test', ['jshint', 'mocha', 'mochaTest']);
|
||||
grunt.registerTask('default', ['test', 'clean', 'docco']);
|
||||
};
|
176
bower_components/observe-shim/LICENSE
vendored
Normal file
176
bower_components/observe-shim/LICENSE
vendored
Normal 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
|
67
bower_components/observe-shim/README.md
vendored
Normal file
67
bower_components/observe-shim/README.md
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
Object.observe shim
|
||||
===================
|
||||
|
||||
See : [The harmony proposal page](http://wiki.ecmascript.org/doku.php?id=harmony:observe).
|
||||
|
||||
Goal:
|
||||
----
|
||||
|
||||
This shim provides an implementation of the algorithms described in the harmony proposal, and is intended to work on all ES5-compliant browsers.
|
||||
|
||||
|
||||
Dependencies :
|
||||
--------------
|
||||
|
||||
While this implementation does not have dependencies, it tries to use "setImmediate" if present, and fall back on setTimeout if it is not, it is recommended to use a setImmediate shim for browsers that do not support it natively. ( A good one can be found [here](https://github.com/NobleJS/setImmediate) )
|
||||
|
||||
Limitations :
|
||||
-------------
|
||||
|
||||
While this shim provides an implementation for the Object methods, and the Notifier prototype described in the proposal, it does not try to catch and notify by any means changes made to an object.
|
||||
Instead it let you call manually the notify method :
|
||||
|
||||
Object.getNotifier(myObject).notify({ type : "updated" , ....});
|
||||
|
||||
ObserveUtils :
|
||||
--------------
|
||||
|
||||
The ['observe-utils.js'](http://github.com/kapit/observe-utils/) utilities that facilitate the use of this shim can be found on his [own repository](http://github.com/kapit/observe-utils/)
|
||||
|
||||
|
||||
Example :
|
||||
-------
|
||||
|
||||
var myObject = {};
|
||||
ObserveUtils.defineObservableProperties(myObject, "foo", "bar");
|
||||
Object.observe(myObject, function (changes) {
|
||||
console.log(changes);
|
||||
});
|
||||
myObject.foo = "Hello";
|
||||
myObject.bar = "World";
|
||||
|
||||
//log
|
||||
|
||||
[
|
||||
{
|
||||
name : "foo",
|
||||
object : myObject,
|
||||
oldValue : undefined,
|
||||
type : "updated"
|
||||
},
|
||||
{
|
||||
name : "bar",
|
||||
object : myObject,
|
||||
oldValue : undefined,
|
||||
type : "updated"
|
||||
}
|
||||
]
|
||||
|
||||
Build And Test:
|
||||
---------------
|
||||
|
||||
Require [bower](https://github.com/twitter/bower) and [grunt-cli](https://github.com/gruntjs/grunt-cli) installed on your machine.
|
||||
|
||||
npm install & bower install
|
||||
grunt // test and build
|
||||
grunt test // test only
|
||||
|
10
bower_components/observe-shim/bower.json
vendored
Normal file
10
bower_components/observe-shim/bower.json
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "observe-shim",
|
||||
"version": "0.4.2",
|
||||
"main": "lib/observe-shim.js",
|
||||
"devDependencies": {
|
||||
"mocha" : "~1.8.x",
|
||||
"expect" : "~0.2.0",
|
||||
"sinon" : "http://sinonjs.org/releases/sinon-1.6.0.js"
|
||||
}
|
||||
}
|
13
bower_components/observe-shim/component.json
vendored
Normal file
13
bower_components/observe-shim/component.json
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "observe-shim",
|
||||
"version": "0.4.2",
|
||||
"description": "An Object.observe harmony proposal shim",
|
||||
"main": "lib/observe-shim.js",
|
||||
"repo": "KapIT/observe-shim",
|
||||
"scripts": ["lib/observe-shim.js"],
|
||||
"keywords": [
|
||||
"observe",
|
||||
"data binding"
|
||||
],
|
||||
"license": "Apache"
|
||||
}
|
192
bower_components/observe-shim/docs/docco.css
vendored
Normal file
192
bower_components/observe-shim/docs/docco.css
vendored
Normal file
@ -0,0 +1,192 @@
|
||||
/*--------------------- Layout and Typography ----------------------------*/
|
||||
body {
|
||||
font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
|
||||
font-size: 15px;
|
||||
line-height: 22px;
|
||||
color: #252519;
|
||||
margin: 0; padding: 0;
|
||||
}
|
||||
a {
|
||||
color: #261a3b;
|
||||
}
|
||||
a:visited {
|
||||
color: #261a3b;
|
||||
}
|
||||
p {
|
||||
margin: 0 0 15px 0;
|
||||
}
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
margin: 0px 0 15px 0;
|
||||
}
|
||||
h1 {
|
||||
margin-top: 40px;
|
||||
}
|
||||
hr {
|
||||
border: 0 none;
|
||||
border-top: 1px solid #e5e5ee;
|
||||
height: 1px;
|
||||
margin: 20px 0;
|
||||
}
|
||||
#container {
|
||||
position: relative;
|
||||
}
|
||||
#background {
|
||||
position: fixed;
|
||||
top: 0; left: 525px; right: 0; bottom: 0;
|
||||
background: #f5f5ff;
|
||||
border-left: 1px solid #e5e5ee;
|
||||
z-index: -1;
|
||||
}
|
||||
#jump_to, #jump_page {
|
||||
background: white;
|
||||
-webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777;
|
||||
-webkit-border-bottom-left-radius: 5px; -moz-border-radius-bottomleft: 5px;
|
||||
font: 10px Arial;
|
||||
text-transform: uppercase;
|
||||
cursor: pointer;
|
||||
text-align: right;
|
||||
}
|
||||
#jump_to, #jump_wrapper {
|
||||
position: fixed;
|
||||
right: 0; top: 0;
|
||||
padding: 5px 10px;
|
||||
}
|
||||
#jump_wrapper {
|
||||
padding: 0;
|
||||
display: none;
|
||||
}
|
||||
#jump_to:hover #jump_wrapper {
|
||||
display: block;
|
||||
}
|
||||
#jump_page {
|
||||
padding: 5px 0 3px;
|
||||
margin: 0 0 25px 25px;
|
||||
}
|
||||
#jump_page .source {
|
||||
display: block;
|
||||
padding: 5px 10px;
|
||||
text-decoration: none;
|
||||
border-top: 1px solid #eee;
|
||||
}
|
||||
#jump_page .source:hover {
|
||||
background: #f5f5ff;
|
||||
}
|
||||
#jump_page .source:first-child {
|
||||
}
|
||||
table td {
|
||||
border: 0;
|
||||
outline: 0;
|
||||
}
|
||||
td.docs, th.docs {
|
||||
max-width: 450px;
|
||||
min-width: 450px;
|
||||
min-height: 5px;
|
||||
padding: 10px 25px 1px 50px;
|
||||
overflow-x: hidden;
|
||||
vertical-align: top;
|
||||
text-align: left;
|
||||
}
|
||||
.docs pre {
|
||||
margin: 15px 0 15px;
|
||||
padding-left: 15px;
|
||||
}
|
||||
.docs p tt, .docs p code {
|
||||
background: #f8f8ff;
|
||||
border: 1px solid #dedede;
|
||||
font-size: 12px;
|
||||
padding: 0 0.2em;
|
||||
}
|
||||
.pilwrap {
|
||||
position: relative;
|
||||
}
|
||||
.pilcrow {
|
||||
font: 12px Arial;
|
||||
text-decoration: none;
|
||||
color: #454545;
|
||||
position: absolute;
|
||||
top: 3px; left: -20px;
|
||||
padding: 1px 2px;
|
||||
opacity: 0;
|
||||
-webkit-transition: opacity 0.2s linear;
|
||||
}
|
||||
td.docs:hover .pilcrow {
|
||||
opacity: 1;
|
||||
}
|
||||
td.code, th.code {
|
||||
padding: 14px 15px 16px 25px;
|
||||
width: 100%;
|
||||
vertical-align: top;
|
||||
background: #f5f5ff;
|
||||
border-left: 1px solid #e5e5ee;
|
||||
}
|
||||
pre, tt, code {
|
||||
font-size: 12px; line-height: 18px;
|
||||
font-family: Menlo, Monaco, Consolas, "Lucida Console", monospace;
|
||||
margin: 0; padding: 0;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------- Syntax Highlighting -----------------------------*/
|
||||
td.linenos { background-color: #f0f0f0; padding-right: 10px; }
|
||||
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
|
||||
body .hll { background-color: #ffffcc }
|
||||
body .c { color: #408080; font-style: italic } /* Comment */
|
||||
body .err { border: 1px solid #FF0000 } /* Error */
|
||||
body .k { color: #954121 } /* Keyword */
|
||||
body .o { color: #666666 } /* Operator */
|
||||
body .cm { color: #408080; font-style: italic } /* Comment.Multiline */
|
||||
body .cp { color: #BC7A00 } /* Comment.Preproc */
|
||||
body .c1 { color: #408080; font-style: italic } /* Comment.Single */
|
||||
body .cs { color: #408080; font-style: italic } /* Comment.Special */
|
||||
body .gd { color: #A00000 } /* Generic.Deleted */
|
||||
body .ge { font-style: italic } /* Generic.Emph */
|
||||
body .gr { color: #FF0000 } /* Generic.Error */
|
||||
body .gh { color: #000080; font-weight: bold } /* Generic.Heading */
|
||||
body .gi { color: #00A000 } /* Generic.Inserted */
|
||||
body .go { color: #808080 } /* Generic.Output */
|
||||
body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
|
||||
body .gs { font-weight: bold } /* Generic.Strong */
|
||||
body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
|
||||
body .gt { color: #0040D0 } /* Generic.Traceback */
|
||||
body .kc { color: #954121 } /* Keyword.Constant */
|
||||
body .kd { color: #954121; font-weight: bold } /* Keyword.Declaration */
|
||||
body .kn { color: #954121; font-weight: bold } /* Keyword.Namespace */
|
||||
body .kp { color: #954121 } /* Keyword.Pseudo */
|
||||
body .kr { color: #954121; font-weight: bold } /* Keyword.Reserved */
|
||||
body .kt { color: #B00040 } /* Keyword.Type */
|
||||
body .m { color: #666666 } /* Literal.Number */
|
||||
body .s { color: #219161 } /* Literal.String */
|
||||
body .na { color: #7D9029 } /* Name.Attribute */
|
||||
body .nb { color: #954121 } /* Name.Builtin */
|
||||
body .nc { color: #0000FF; font-weight: bold } /* Name.Class */
|
||||
body .no { color: #880000 } /* Name.Constant */
|
||||
body .nd { color: #AA22FF } /* Name.Decorator */
|
||||
body .ni { color: #999999; font-weight: bold } /* Name.Entity */
|
||||
body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
|
||||
body .nf { color: #0000FF } /* Name.Function */
|
||||
body .nl { color: #A0A000 } /* Name.Label */
|
||||
body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
|
||||
body .nt { color: #954121; font-weight: bold } /* Name.Tag */
|
||||
body .nv { color: #19469D } /* Name.Variable */
|
||||
body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
|
||||
body .w { color: #bbbbbb } /* Text.Whitespace */
|
||||
body .mf { color: #666666 } /* Literal.Number.Float */
|
||||
body .mh { color: #666666 } /* Literal.Number.Hex */
|
||||
body .mi { color: #666666 } /* Literal.Number.Integer */
|
||||
body .mo { color: #666666 } /* Literal.Number.Oct */
|
||||
body .sb { color: #219161 } /* Literal.String.Backtick */
|
||||
body .sc { color: #219161 } /* Literal.String.Char */
|
||||
body .sd { color: #219161; font-style: italic } /* Literal.String.Doc */
|
||||
body .s2 { color: #219161 } /* Literal.String.Double */
|
||||
body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
|
||||
body .sh { color: #219161 } /* Literal.String.Heredoc */
|
||||
body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
|
||||
body .sx { color: #954121 } /* Literal.String.Other */
|
||||
body .sr { color: #BB6688 } /* Literal.String.Regex */
|
||||
body .s1 { color: #219161 } /* Literal.String.Single */
|
||||
body .ss { color: #19469D } /* Literal.String.Symbol */
|
||||
body .bp { color: #954121 } /* Name.Builtin.Pseudo */
|
||||
body .vc { color: #19469D } /* Name.Variable.Class */
|
||||
body .vg { color: #19469D } /* Name.Variable.Global */
|
||||
body .vi { color: #19469D } /* Name.Variable.Instance */
|
||||
body .il { color: #666666 } /* Literal.Number.Integer.Long */
|
428
bower_components/observe-shim/docs/observe-shim.html
vendored
Normal file
428
bower_components/observe-shim/docs/observe-shim.html
vendored
Normal file
@ -0,0 +1,428 @@
|
||||
<!DOCTYPE html> <html> <head> <title>observe-shim.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> observe-shim.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">¶</a> </div> <p>Copyright 2012 Kap IT (http://www.kapit.fr/)</p>
|
||||
|
||||
<p>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</p>
|
||||
|
||||
<pre><code> http://www.apache.org/licenses/LICENSE-2.0
|
||||
</code></pre>
|
||||
|
||||
<p>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/),</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">¶</a> </div> <h1>Object.observe Shim</h1> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">¶</a> </div> <p><em>See <a href="http://wiki.ecmascript.org/doku.php?id=harmony:observe">The harmony proposal page</a></em></p> </td> <td class="code"> <div class="highlight"><pre><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">global</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="s1">'use strict'</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">¶</a> </div> <h2>Utilities</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">¶</a> </div> <p>setImmediate shim used to deliver changes records asynchronously
|
||||
use setImmediate if available</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">setImmediate</span> <span class="o">=</span> <span class="nx">global</span><span class="p">.</span><span class="nx">setImmediate</span> <span class="o">||</span> <span class="nx">global</span><span class="p">.</span><span class="nx">msSetImmediate</span><span class="p">,</span>
|
||||
<span class="nx">clearImmediate</span> <span class="o">=</span> <span class="nx">global</span><span class="p">.</span><span class="nx">clearImmediate</span> <span class="o">||</span> <span class="nx">global</span><span class="p">.</span><span class="nx">msClearImmediate</span><span class="p">;</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">setImmediate</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">¶</a> </div> <p>fallback on setTimeout if not</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">setImmediate</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">func</span><span class="p">,</span> <span class="nx">args</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">return</span> <span class="nx">setTimeout</span><span class="p">(</span><span class="nx">func</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">args</span><span class="p">);</span>
|
||||
<span class="p">};</span>
|
||||
<span class="nx">clearImmediate</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">id</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="nx">clearTimeout</span><span class="p">(</span><span class="nx">id</span><span class="p">);</span>
|
||||
<span class="p">};</span>
|
||||
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">¶</a> </div> <h2>WeakMap</h2> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">PrivateMap</span><span class="p">;</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">WeakMap</span> <span class="o">!==</span> <span class="s1">'undefined'</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">¶</a> </div> <p>use weakmap if defined</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">PrivateMap</span> <span class="o">=</span> <span class="nx">WeakMap</span><span class="p">;</span>
|
||||
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">¶</a> </div> <p>else use ses like shim of WeakMap</p> </td> <td class="code"> <div class="highlight"><pre> <span class="cm">/* jshint -W016 */</span>
|
||||
<span class="kd">var</span> <span class="nx">HIDDEN_PREFIX</span> <span class="o">=</span> <span class="s1">'__weakmap:'</span> <span class="o">+</span> <span class="p">(</span><span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">()</span> <span class="o">*</span> <span class="mi">1</span><span class="nx">e9</span> <span class="o">>>></span> <span class="mi">0</span><span class="p">),</span>
|
||||
<span class="nx">counter</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">Date</span><span class="p">().</span><span class="nx">getTime</span><span class="p">()</span> <span class="o">%</span> <span class="mi">1</span><span class="nx">e9</span><span class="p">,</span>
|
||||
<span class="nx">mascot</span> <span class="o">=</span> <span class="p">{};</span>
|
||||
|
||||
<span class="nx">PrivateMap</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
|
||||
<span class="k">this</span><span class="p">.</span><span class="nx">name</span> <span class="o">=</span> <span class="nx">HIDDEN_PREFIX</span> <span class="o">+</span> <span class="p">(</span><span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">()</span> <span class="o">*</span> <span class="mi">1</span><span class="nx">e9</span> <span class="o">>>></span> <span class="mi">0</span><span class="p">)</span> <span class="o">+</span> <span class="p">(</span><span class="nx">counter</span><span class="o">++</span> <span class="o">+</span> <span class="s1">'__'</span><span class="p">);</span>
|
||||
<span class="p">};</span>
|
||||
|
||||
<span class="nx">PrivateMap</span><span class="p">.</span><span class="nx">prototype</span> <span class="o">=</span> <span class="p">{</span>
|
||||
<span class="nx">has</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">return</span> <span class="nx">key</span> <span class="o">&&</span> <span class="nx">key</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">name</span><span class="p">);</span>
|
||||
<span class="p">},</span>
|
||||
|
||||
<span class="nx">get</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="kd">var</span> <span class="nx">value</span> <span class="o">=</span> <span class="nx">key</span> <span class="o">&&</span> <span class="nx">key</span><span class="p">[</span><span class="k">this</span><span class="p">.</span><span class="nx">name</span><span class="p">];</span>
|
||||
<span class="k">return</span> <span class="nx">value</span> <span class="o">===</span> <span class="nx">mascot</span> <span class="o">?</span> <span class="kc">undefined</span> <span class="o">:</span> <span class="nx">value</span><span class="p">;</span>
|
||||
<span class="p">},</span>
|
||||
|
||||
<span class="nx">set</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="nb">Object</span><span class="p">.</span><span class="nx">defineProperty</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">name</span><span class="p">,</span> <span class="p">{</span>
|
||||
<span class="nx">value</span> <span class="o">:</span> <span class="k">typeof</span> <span class="nx">value</span> <span class="o">===</span> <span class="s1">'undefined'</span> <span class="o">?</span> <span class="nx">mascot</span> <span class="o">:</span> <span class="nx">value</span><span class="p">,</span>
|
||||
<span class="nx">enumerable</span><span class="o">:</span> <span class="kc">false</span><span class="p">,</span>
|
||||
<span class="nx">writable</span> <span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
|
||||
<span class="nx">configurable</span><span class="o">:</span> <span class="kc">true</span>
|
||||
<span class="p">});</span>
|
||||
<span class="p">},</span>
|
||||
|
||||
<span class="s1">'delete'</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">return</span> <span class="k">delete</span> <span class="nx">key</span><span class="p">[</span><span class="k">this</span><span class="p">.</span><span class="nx">name</span><span class="p">];</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">};</span>
|
||||
|
||||
|
||||
<span class="kd">var</span> <span class="nx">getOwnPropertyName</span> <span class="o">=</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">getOwnPropertyNames</span><span class="p">;</span>
|
||||
<span class="nb">Object</span><span class="p">.</span><span class="nx">defineProperty</span><span class="p">(</span><span class="nb">Object</span><span class="p">,</span> <span class="s1">'getOwnPropertyNames'</span><span class="p">,</span> <span class="p">{</span>
|
||||
<span class="nx">value</span><span class="o">:</span> <span class="kd">function</span> <span class="nx">fakeGetOwnPropertyNames</span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">return</span> <span class="nx">getOwnPropertyName</span><span class="p">(</span><span class="nx">obj</span><span class="p">).</span><span class="nx">filter</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">return</span> <span class="nx">name</span><span class="p">.</span><span class="nx">substr</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nx">HIDDEN_PREFIX</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span> <span class="o">!==</span> <span class="nx">HIDDEN_PREFIX</span><span class="p">;</span>
|
||||
<span class="p">});</span>
|
||||
<span class="p">},</span>
|
||||
<span class="nx">writable</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
|
||||
<span class="nx">enumerable</span><span class="o">:</span> <span class="kc">false</span><span class="p">,</span>
|
||||
<span class="nx">configurable</span><span class="o">:</span> <span class="kc">true</span>
|
||||
<span class="p">});</span>
|
||||
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">¶</a> </div> <h2>Internal Properties</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">¶</a> </div> <p>An ordered list used to provide a deterministic ordering in which callbacks are called.
|
||||
<a href="http://wiki.ecmascript.org/doku.php?id=harmony:observe_internals#observercallbacks">Corresponding Section in ECMAScript wiki</a></p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">observerCallbacks</span> <span class="o">=</span> <span class="p">[];</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">¶</a> </div> <p>This object is used as the prototype of all the notifiers that are returned by Object.getNotifier(O).
|
||||
<a href="http://wiki.ecmascript.org/doku.php?id=harmony:observe_internals#notifierprototype">Corresponding Section in ECMAScript wiki</a></p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">NotifierPrototype</span> <span class="o">=</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span><span class="nb">Object</span><span class="p">.</span><span class="nx">prototype</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">¶</a> </div> <p>Used to store immediate uid reference</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">changeDeliveryImmediateUid</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">¶</a> </div> <p>Used to schedule a call to _deliverAllChangeRecords</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">setUpChangesDelivery</span><span class="p">()</span> <span class="p">{</span>
|
||||
<span class="nx">clearImmediate</span><span class="p">(</span><span class="nx">changeDeliveryImmediateUid</span><span class="p">);</span>
|
||||
<span class="nx">changeDeliveryImmediateUid</span> <span class="o">=</span> <span class="nx">setImmediate</span><span class="p">(</span><span class="nx">_deliverAllChangeRecords</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
|
||||
<span class="nb">Object</span><span class="p">.</span><span class="nx">defineProperty</span><span class="p">(</span><span class="nx">NotifierPrototype</span><span class="p">,</span> <span class="s1">'notify'</span><span class="p">,</span> <span class="p">{</span>
|
||||
<span class="nx">value</span><span class="o">:</span> <span class="kd">function</span> <span class="nx">notify</span><span class="p">(</span><span class="nx">changeRecord</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="kd">var</span> <span class="nx">notifier</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="nb">Object</span><span class="p">(</span><span class="nx">notifier</span><span class="p">)</span> <span class="o">!==</span> <span class="nx">notifier</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nx">TypeError</span><span class="p">(</span><span class="s1">'this must be an Object, given '</span> <span class="o">+</span> <span class="nx">notifier</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">notifier</span><span class="p">.</span><span class="nx">__target</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">return</span><span class="p">;</span>
|
||||
<span class="p">}</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="nb">Object</span><span class="p">(</span><span class="nx">changeRecord</span><span class="p">)</span> <span class="o">!==</span> <span class="nx">changeRecord</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nx">TypeError</span><span class="p">(</span><span class="s1">'changeRecord must be an Object, given '</span> <span class="o">+</span> <span class="nx">changeRecord</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
|
||||
|
||||
<span class="kd">var</span> <span class="nx">type</span> <span class="o">=</span> <span class="nx">changeRecord</span><span class="p">.</span><span class="nx">type</span><span class="p">;</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">type</span> <span class="o">!==</span> <span class="s1">'string'</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nx">TypeError</span><span class="p">(</span><span class="s1">'changeRecord.type must be a string, given '</span> <span class="o">+</span> <span class="nx">type</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
|
||||
<span class="kd">var</span> <span class="nx">changeObservers</span> <span class="o">=</span> <span class="nx">changeObserversMap</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">notifier</span><span class="p">);</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">changeObservers</span> <span class="o">||</span> <span class="nx">changeObservers</span><span class="p">.</span><span class="nx">length</span> <span class="o">===</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">return</span><span class="p">;</span>
|
||||
<span class="p">}</span>
|
||||
<span class="kd">var</span> <span class="nx">target</span> <span class="o">=</span> <span class="nx">notifier</span><span class="p">.</span><span class="nx">__target</span><span class="p">,</span>
|
||||
<span class="nx">newRecord</span> <span class="o">=</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span><span class="nb">Object</span><span class="p">.</span><span class="nx">prototype</span><span class="p">,</span> <span class="p">{</span>
|
||||
<span class="s1">'object'</span><span class="o">:</span> <span class="p">{</span>
|
||||
<span class="nx">value</span><span class="o">:</span> <span class="nx">target</span><span class="p">,</span>
|
||||
<span class="nx">writable</span> <span class="o">:</span> <span class="kc">false</span><span class="p">,</span>
|
||||
<span class="nx">enumerable</span> <span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
|
||||
<span class="nx">configurable</span><span class="o">:</span> <span class="kc">false</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">});</span>
|
||||
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">prop</span> <span class="k">in</span> <span class="nx">changeRecord</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="nx">prop</span> <span class="o">!==</span> <span class="s1">'object'</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="kd">var</span> <span class="nx">value</span> <span class="o">=</span> <span class="nx">changeRecord</span><span class="p">[</span><span class="nx">prop</span><span class="p">];</span>
|
||||
<span class="nb">Object</span><span class="p">.</span><span class="nx">defineProperty</span><span class="p">(</span><span class="nx">newRecord</span><span class="p">,</span> <span class="nx">prop</span><span class="p">,</span> <span class="p">{</span>
|
||||
<span class="nx">value</span><span class="o">:</span> <span class="nx">value</span><span class="p">,</span>
|
||||
<span class="nx">writable</span> <span class="o">:</span> <span class="kc">false</span><span class="p">,</span>
|
||||
<span class="nx">enumerable</span> <span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
|
||||
<span class="nx">configurable</span><span class="o">:</span> <span class="kc">false</span>
|
||||
<span class="p">});</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">}</span>
|
||||
<span class="nb">Object</span><span class="p">.</span><span class="nx">preventExtensions</span><span class="p">(</span><span class="nx">newRecord</span><span class="p">);</span>
|
||||
<span class="nx">_enqueueChangeRecord</span><span class="p">(</span><span class="nx">notifier</span><span class="p">.</span><span class="nx">__target</span><span class="p">,</span> <span class="nx">newRecord</span><span class="p">);</span>
|
||||
<span class="p">},</span>
|
||||
<span class="nx">writable</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
|
||||
<span class="nx">enumerable</span><span class="o">:</span> <span class="kc">false</span><span class="p">,</span>
|
||||
<span class="nx">configurable</span> <span class="o">:</span> <span class="kc">true</span>
|
||||
<span class="p">});</span>
|
||||
|
||||
<span class="nb">Object</span><span class="p">.</span><span class="nx">defineProperty</span><span class="p">(</span><span class="nx">NotifierPrototype</span><span class="p">,</span> <span class="s1">'performChange'</span><span class="p">,</span> <span class="p">{</span>
|
||||
<span class="nx">value</span><span class="o">:</span> <span class="kd">function</span> <span class="nx">performChange</span><span class="p">(</span><span class="nx">changeType</span><span class="p">,</span> <span class="nx">changeFn</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="kd">var</span> <span class="nx">notifier</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="nb">Object</span><span class="p">(</span><span class="nx">notifier</span><span class="p">)</span> <span class="o">!==</span> <span class="nx">notifier</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nx">TypeError</span><span class="p">(</span><span class="s1">'this must be an Object, given '</span> <span class="o">+</span> <span class="nx">notifier</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">notifier</span><span class="p">.</span><span class="nx">__target</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">return</span><span class="p">;</span>
|
||||
<span class="p">}</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">changeType</span> <span class="o">!==</span> <span class="s1">'string'</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nx">TypeError</span><span class="p">(</span><span class="s1">'changeType must be a string given '</span> <span class="o">+</span> <span class="nx">notifier</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">changeFn</span> <span class="o">!==</span> <span class="s1">'function'</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nx">TypeError</span><span class="p">(</span><span class="s1">'changeFn must be a function, given '</span> <span class="o">+</span> <span class="nx">changeFn</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
|
||||
<span class="nx">_beginChange</span><span class="p">(</span><span class="nx">notifier</span><span class="p">.</span><span class="nx">__target</span><span class="p">,</span> <span class="nx">changeType</span><span class="p">);</span>
|
||||
<span class="kd">var</span> <span class="nx">error</span><span class="p">,</span> <span class="nx">changeRecord</span><span class="p">;</span>
|
||||
<span class="k">try</span> <span class="p">{</span>
|
||||
<span class="nx">changeRecord</span> <span class="o">=</span> <span class="nx">changeFn</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="kc">undefined</span><span class="p">);</span>
|
||||
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="nx">error</span> <span class="o">=</span> <span class="nx">e</span><span class="p">;</span>
|
||||
<span class="p">}</span>
|
||||
<span class="nx">_endChange</span><span class="p">(</span><span class="nx">notifier</span><span class="p">.</span><span class="nx">__target</span><span class="p">,</span> <span class="nx">changeType</span><span class="p">);</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">error</span> <span class="o">!==</span> <span class="s1">'undefined'</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">throw</span> <span class="nx">error</span><span class="p">;</span>
|
||||
<span class="p">}</span>
|
||||
|
||||
<span class="kd">var</span> <span class="nx">changeObservers</span> <span class="o">=</span> <span class="nx">changeObserversMap</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">notifier</span><span class="p">);</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="nx">changeObservers</span><span class="p">.</span><span class="nx">length</span> <span class="o">===</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">return</span><span class="p">;</span>
|
||||
<span class="p">}</span>
|
||||
|
||||
<span class="kd">var</span> <span class="nx">target</span> <span class="o">=</span> <span class="nx">notifier</span><span class="p">.</span><span class="nx">__target</span><span class="p">,</span>
|
||||
<span class="nx">newRecord</span> <span class="o">=</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span><span class="nb">Object</span><span class="p">.</span><span class="nx">prototype</span><span class="p">,</span> <span class="p">{</span>
|
||||
<span class="s1">'object'</span><span class="o">:</span> <span class="p">{</span>
|
||||
<span class="nx">value</span><span class="o">:</span> <span class="nx">target</span><span class="p">,</span>
|
||||
<span class="nx">writable</span> <span class="o">:</span> <span class="kc">false</span><span class="p">,</span>
|
||||
<span class="nx">enumerable</span> <span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
|
||||
<span class="nx">configurable</span><span class="o">:</span> <span class="kc">false</span>
|
||||
<span class="p">},</span>
|
||||
<span class="s1">'type'</span><span class="o">:</span> <span class="p">{</span>
|
||||
<span class="nx">value</span><span class="o">:</span> <span class="nx">changeType</span><span class="p">,</span>
|
||||
<span class="nx">writable</span> <span class="o">:</span> <span class="kc">false</span><span class="p">,</span>
|
||||
<span class="nx">enumerable</span> <span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
|
||||
<span class="nx">configurable</span><span class="o">:</span> <span class="kc">false</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">});</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">changeRecord</span> <span class="o">!==</span> <span class="s1">'undefined'</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">prop</span> <span class="k">in</span> <span class="nx">changeRecord</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="nx">prop</span> <span class="o">!==</span> <span class="s1">'object'</span> <span class="o">&&</span> <span class="nx">prop</span> <span class="o">!==</span> <span class="s1">'type'</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="kd">var</span> <span class="nx">value</span> <span class="o">=</span> <span class="nx">changeRecord</span><span class="p">[</span><span class="nx">prop</span><span class="p">];</span>
|
||||
<span class="nb">Object</span><span class="p">.</span><span class="nx">defineProperty</span><span class="p">(</span><span class="nx">newRecord</span><span class="p">,</span> <span class="nx">prop</span><span class="p">,</span> <span class="p">{</span>
|
||||
<span class="nx">value</span><span class="o">:</span> <span class="nx">value</span><span class="p">,</span>
|
||||
<span class="nx">writable</span> <span class="o">:</span> <span class="kc">false</span><span class="p">,</span>
|
||||
<span class="nx">enumerable</span> <span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
|
||||
<span class="nx">configurable</span><span class="o">:</span> <span class="kc">false</span>
|
||||
<span class="p">});</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">}</span>
|
||||
|
||||
<span class="nb">Object</span><span class="p">.</span><span class="nx">preventExtensions</span><span class="p">(</span><span class="nx">newRecord</span><span class="p">);</span>
|
||||
<span class="nx">_enqueueChangeRecord</span><span class="p">(</span><span class="nx">notifier</span><span class="p">.</span><span class="nx">__target</span><span class="p">,</span> <span class="nx">newRecord</span><span class="p">);</span>
|
||||
|
||||
<span class="p">},</span>
|
||||
<span class="nx">writable</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
|
||||
<span class="nx">enumerable</span><span class="o">:</span> <span class="kc">false</span><span class="p">,</span>
|
||||
<span class="nx">configurable</span> <span class="o">:</span> <span class="kc">true</span>
|
||||
<span class="p">});</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">¶</a> </div> <p>Implementation of the internal algorithm 'BeginChange'
|
||||
described in the proposal.
|
||||
<a href="http://wiki.ecmascript.org/doku.php?id=harmony:observe_internals#beginchange">Corresponding Section in ECMAScript wiki</a></p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">_beginChange</span><span class="p">(</span><span class="nx">object</span><span class="p">,</span> <span class="nx">changeType</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="kd">var</span> <span class="nx">notifier</span> <span class="o">=</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">getNotifier</span><span class="p">(</span><span class="nx">object</span><span class="p">),</span>
|
||||
<span class="nx">activeChanges</span> <span class="o">=</span> <span class="nx">activeChangesMap</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">notifier</span><span class="p">),</span>
|
||||
<span class="nx">changeCount</span> <span class="o">=</span> <span class="nx">activeChangesMap</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">notifier</span><span class="p">)[</span><span class="nx">changeType</span><span class="p">];</span>
|
||||
<span class="nx">activeChanges</span><span class="p">[</span><span class="nx">changeType</span><span class="p">]</span> <span class="o">=</span> <span class="k">typeof</span> <span class="nx">changeCount</span> <span class="o">===</span> <span class="s1">'undefined'</span> <span class="o">?</span> <span class="mi">1</span> <span class="o">:</span> <span class="nx">changeCount</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
|
||||
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">¶</a> </div> <p>Implementation of the internal algorithm 'EndChange'
|
||||
described in the proposal.
|
||||
<a href="http://wiki.ecmascript.org/doku.php?id=harmony:observe_internals#endchange">Corresponding Section in ECMAScript wiki</a></p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">_endChange</span><span class="p">(</span><span class="nx">object</span><span class="p">,</span> <span class="nx">changeType</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="kd">var</span> <span class="nx">notifier</span> <span class="o">=</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">getNotifier</span><span class="p">(</span><span class="nx">object</span><span class="p">),</span>
|
||||
<span class="nx">activeChanges</span> <span class="o">=</span> <span class="nx">activeChangesMap</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">notifier</span><span class="p">),</span>
|
||||
<span class="nx">changeCount</span> <span class="o">=</span> <span class="nx">activeChangesMap</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">notifier</span><span class="p">)[</span><span class="nx">changeType</span><span class="p">];</span>
|
||||
<span class="nx">activeChanges</span><span class="p">[</span><span class="nx">changeType</span><span class="p">]</span> <span class="o">=</span> <span class="nx">changeCount</span> <span class="o">></span> <span class="mi">0</span> <span class="o">?</span> <span class="nx">changeCount</span> <span class="o">-</span> <span class="mi">1</span> <span class="o">:</span> <span class="mi">0</span><span class="p">;</span>
|
||||
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">¶</a> </div> <p>Implementation of the internal algorithm 'ShouldDeliverToObserver'
|
||||
described in the proposal.
|
||||
<a href="http://wiki.ecmascript.org/doku.php?id=harmony:observe_internals#shoulddelivertoobserver">Corresponding Section in ECMAScript wiki</a></p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">_shouldDeliverToObserver</span><span class="p">(</span><span class="nx">activeChanges</span><span class="p">,</span> <span class="nx">acceptList</span><span class="p">,</span> <span class="nx">changeType</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="kd">var</span> <span class="nx">doesAccept</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="nx">acceptList</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">l</span> <span class="o">=</span> <span class="nx">acceptList</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">l</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="kd">var</span> <span class="nx">accept</span> <span class="o">=</span> <span class="nx">acceptList</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="nx">activeChanges</span><span class="p">[</span><span class="nx">accept</span><span class="p">]</span> <span class="o">></span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
|
||||
<span class="p">}</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="nx">accept</span> <span class="o">===</span> <span class="nx">changeType</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="nx">doesAccept</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">}</span>
|
||||
<span class="k">return</span> <span class="nx">doesAccept</span><span class="p">;</span>
|
||||
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-18">¶</a> </div> <p>Map used to store corresponding notifier to an object</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">notifierMap</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">PrivateMap</span><span class="p">(),</span>
|
||||
<span class="nx">changeObserversMap</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">PrivateMap</span><span class="p">(),</span>
|
||||
<span class="nx">activeChangesMap</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">PrivateMap</span><span class="p">();</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">¶</a> </div> <p>Implementation of the internal algorithm 'GetNotifier'
|
||||
described in the proposal.
|
||||
<a href="http://wiki.ecmascript.org/doku.php?id=harmony:observe_internals#getnotifier">Corresponding Section in ECMAScript wiki</a></p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">_getNotifier</span><span class="p">(</span><span class="nx">target</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">notifierMap</span><span class="p">.</span><span class="nx">has</span><span class="p">(</span><span class="nx">target</span><span class="p">))</span> <span class="p">{</span>
|
||||
<span class="kd">var</span> <span class="nx">notifier</span> <span class="o">=</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span><span class="nx">NotifierPrototype</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-20"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-20">¶</a> </div> <p>we does not really need to hide this, since anyway the host object is accessible from outside of the
|
||||
implementation. we just make it unwritable</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nb">Object</span><span class="p">.</span><span class="nx">defineProperty</span><span class="p">(</span><span class="nx">notifier</span><span class="p">,</span> <span class="s1">'__target'</span><span class="p">,</span> <span class="p">{</span> <span class="nx">value</span> <span class="o">:</span> <span class="nx">target</span> <span class="p">});</span>
|
||||
<span class="nx">changeObserversMap</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">notifier</span><span class="p">,</span> <span class="p">[]);</span>
|
||||
<span class="nx">activeChangesMap</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">notifier</span><span class="p">,</span> <span class="p">{});</span>
|
||||
<span class="nx">notifierMap</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">target</span><span class="p">,</span> <span class="nx">notifier</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="k">return</span> <span class="nx">notifierMap</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">target</span><span class="p">);</span>
|
||||
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-21"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-21">¶</a> </div> <p>map used to store reference to a list of pending changeRecords
|
||||
in observer callback.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">pendingChangesMap</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">PrivateMap</span><span class="p">();</span></pre></div> </td> </tr> <tr id="section-22"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-22">¶</a> </div> <p>Implementation of the internal algorithm 'EnqueueChangeRecord'
|
||||
described in the proposal.
|
||||
<a href="http://wiki.ecmascript.org/doku.php?id=harmony:observe_internals#enqueuechangerecord">Corresponding Section in ECMAScript wiki</a></p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">_enqueueChangeRecord</span><span class="p">(</span><span class="nx">object</span><span class="p">,</span> <span class="nx">changeRecord</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="kd">var</span> <span class="nx">notifier</span> <span class="o">=</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">getNotifier</span><span class="p">(</span><span class="nx">object</span><span class="p">),</span>
|
||||
<span class="nx">changeType</span> <span class="o">=</span> <span class="nx">changeRecord</span><span class="p">.</span><span class="nx">type</span><span class="p">,</span>
|
||||
<span class="nx">activeChanges</span> <span class="o">=</span> <span class="nx">activeChangesMap</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">notifier</span><span class="p">),</span>
|
||||
<span class="nx">changeObservers</span> <span class="o">=</span> <span class="nx">changeObserversMap</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">notifier</span><span class="p">);</span>
|
||||
|
||||
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">l</span> <span class="o">=</span> <span class="nx">changeObservers</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">l</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="kd">var</span> <span class="nx">observerRecord</span> <span class="o">=</span> <span class="nx">changeObservers</span><span class="p">[</span><span class="nx">i</span><span class="p">],</span>
|
||||
<span class="nx">acceptList</span> <span class="o">=</span> <span class="nx">observerRecord</span><span class="p">.</span><span class="nx">accept</span><span class="p">;</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="nx">_shouldDeliverToObserver</span><span class="p">(</span><span class="nx">activeChanges</span><span class="p">,</span> <span class="nx">acceptList</span><span class="p">,</span> <span class="nx">changeType</span><span class="p">))</span> <span class="p">{</span>
|
||||
<span class="kd">var</span> <span class="nx">observer</span> <span class="o">=</span> <span class="nx">observerRecord</span><span class="p">.</span><span class="nx">callback</span><span class="p">,</span>
|
||||
<span class="nx">pendingChangeRecords</span> <span class="o">=</span> <span class="p">[];</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">pendingChangesMap</span><span class="p">.</span><span class="nx">has</span><span class="p">(</span><span class="nx">observer</span><span class="p">))</span> <span class="p">{</span>
|
||||
<span class="nx">pendingChangesMap</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">observer</span><span class="p">,</span> <span class="nx">pendingChangeRecords</span><span class="p">);</span>
|
||||
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
|
||||
<span class="nx">pendingChangeRecords</span> <span class="o">=</span> <span class="nx">pendingChangesMap</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">observer</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="nx">pendingChangeRecords</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">changeRecord</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">}</span>
|
||||
<span class="nx">setUpChangesDelivery</span><span class="p">();</span>
|
||||
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-23"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-23">¶</a> </div> <p>map used to store a count of associated notifier to a function</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">attachedNotifierCountMap</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">PrivateMap</span><span class="p">();</span></pre></div> </td> </tr> <tr id="section-24"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-24">¶</a> </div> <p>Remove reference all reference to an observer callback,
|
||||
if this one is not used anymore.
|
||||
In the proposal the ObserverCallBack has a weak reference over observers,
|
||||
Without this possibility we need to clean this list to avoid memory leak</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">_cleanObserver</span><span class="p">(</span><span class="nx">observer</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">attachedNotifierCountMap</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">observer</span><span class="p">)</span> <span class="o">&&</span> <span class="o">!</span><span class="nx">pendingChangesMap</span><span class="p">.</span><span class="nx">has</span><span class="p">(</span><span class="nx">observer</span><span class="p">))</span> <span class="p">{</span>
|
||||
<span class="nx">attachedNotifierCountMap</span><span class="p">.</span><span class="k">delete</span><span class="p">(</span><span class="nx">observer</span><span class="p">);</span>
|
||||
<span class="kd">var</span> <span class="nx">index</span> <span class="o">=</span> <span class="nx">observerCallbacks</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">observer</span><span class="p">);</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="nx">index</span> <span class="o">!==</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="nx">observerCallbacks</span><span class="p">.</span><span class="nx">splice</span><span class="p">(</span><span class="nx">index</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-25"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-25">¶</a> </div> <p>Implementation of the internal algorithm 'DeliverChangeRecords'
|
||||
described in the proposal.
|
||||
<a href="http://wiki.ecmascript.org/doku.php?id=harmony:observe_internals#deliverchangerecords">Corresponding Section in ECMAScript wiki</a></p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">_deliverChangeRecords</span><span class="p">(</span><span class="nx">observer</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="kd">var</span> <span class="nx">pendingChangeRecords</span> <span class="o">=</span> <span class="nx">pendingChangesMap</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">observer</span><span class="p">);</span>
|
||||
<span class="nx">pendingChangesMap</span><span class="p">.</span><span class="k">delete</span><span class="p">(</span><span class="nx">observer</span><span class="p">);</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">pendingChangeRecords</span> <span class="o">||</span> <span class="nx">pendingChangeRecords</span><span class="p">.</span><span class="nx">length</span> <span class="o">===</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
|
||||
<span class="p">}</span>
|
||||
<span class="k">try</span> <span class="p">{</span>
|
||||
<span class="nx">observer</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="kc">undefined</span><span class="p">,</span> <span class="nx">pendingChangeRecords</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="k">catch</span> <span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span> <span class="p">}</span>
|
||||
|
||||
<span class="nx">_cleanObserver</span><span class="p">(</span><span class="nx">observer</span><span class="p">);</span>
|
||||
<span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
|
||||
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-26"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-26">¶</a> </div> <p>Implementation of the internal algorithm 'DeliverAllChangeRecords'
|
||||
described in the proposal.
|
||||
<a href="http://wiki.ecmascript.org/doku.php?id=harmony:observe_internals#deliverallchangerecords">Corresponding Section in ECMAScript wiki</a></p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">_deliverAllChangeRecords</span><span class="p">()</span> <span class="p">{</span>
|
||||
<span class="kd">var</span> <span class="nx">observers</span> <span class="o">=</span> <span class="nx">observerCallbacks</span><span class="p">.</span><span class="nx">slice</span><span class="p">();</span>
|
||||
<span class="kd">var</span> <span class="nx">anyWorkDone</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
|
||||
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">l</span> <span class="o">=</span> <span class="nx">observers</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">l</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="kd">var</span> <span class="nx">observer</span> <span class="o">=</span> <span class="nx">observers</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="nx">_deliverChangeRecords</span><span class="p">(</span><span class="nx">observer</span><span class="p">))</span> <span class="p">{</span>
|
||||
<span class="nx">anyWorkDone</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">}</span>
|
||||
<span class="k">return</span> <span class="nx">anyWorkDone</span><span class="p">;</span>
|
||||
<span class="p">}</span>
|
||||
|
||||
|
||||
<span class="nb">Object</span><span class="p">.</span><span class="nx">defineProperties</span><span class="p">(</span><span class="nb">Object</span><span class="p">,</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-27"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-27">¶</a> </div> <p>Implementation of the public api 'Object.observe'
|
||||
described in the proposal.
|
||||
<a href="http://wiki.ecmascript.org/doku.php?id=harmony:observe_public_api#object.observe">Corresponding Section in ECMAScript wiki</a></p> </td> <td class="code"> <div class="highlight"><pre> <span class="s1">'observe'</span><span class="o">:</span> <span class="p">{</span>
|
||||
<span class="nx">value</span><span class="o">:</span> <span class="kd">function</span> <span class="nx">observe</span><span class="p">(</span><span class="nx">target</span><span class="p">,</span> <span class="nx">callback</span><span class="p">,</span> <span class="nx">accept</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="nb">Object</span><span class="p">(</span><span class="nx">target</span><span class="p">)</span> <span class="o">!==</span> <span class="nx">target</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nx">TypeError</span><span class="p">(</span><span class="s1">'target must be an Object, given '</span> <span class="o">+</span> <span class="nx">target</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">callback</span> <span class="o">!==</span> <span class="s1">'function'</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nx">TypeError</span><span class="p">(</span><span class="s1">'observer must be a function, given '</span> <span class="o">+</span> <span class="nx">callback</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="nb">Object</span><span class="p">.</span><span class="nx">isFrozen</span><span class="p">(</span><span class="nx">callback</span><span class="p">))</span> <span class="p">{</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nx">TypeError</span><span class="p">(</span><span class="s1">'observer cannot be frozen'</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
|
||||
<span class="kd">var</span> <span class="nx">acceptList</span><span class="p">;</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">accept</span> <span class="o">===</span> <span class="s1">'undefined'</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="nx">acceptList</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'add'</span><span class="p">,</span> <span class="s1">'update'</span><span class="p">,</span> <span class="s1">'delete'</span><span class="p">,</span> <span class="s1">'reconfigure'</span><span class="p">,</span> <span class="s1">'setPrototype'</span><span class="p">,</span> <span class="s1">'preventExtensions'</span><span class="p">];</span>
|
||||
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="nb">Object</span><span class="p">(</span><span class="nx">accept</span><span class="p">)</span> <span class="o">!==</span> <span class="nx">accept</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nx">TypeError</span><span class="p">(</span><span class="s1">'accept must be an object, given '</span> <span class="o">+</span> <span class="nx">accept</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="kd">var</span> <span class="nx">len</span> <span class="o">=</span> <span class="nx">accept</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">len</span> <span class="o">!==</span> <span class="s1">'number'</span> <span class="o">||</span> <span class="nx">len</span> <span class="o">>>></span> <span class="mi">0</span> <span class="o">!==</span> <span class="nx">len</span> <span class="o">||</span> <span class="nx">len</span> <span class="o"><</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nx">TypeError</span><span class="p">(</span><span class="s1">'the \'length\' property of accept must be a positive integer, given '</span> <span class="o">+</span> <span class="nx">len</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
|
||||
<span class="kd">var</span> <span class="nx">nextIndex</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
|
||||
<span class="nx">acceptList</span> <span class="o">=</span> <span class="p">[];</span>
|
||||
<span class="k">while</span> <span class="p">(</span><span class="nx">nextIndex</span> <span class="o"><</span> <span class="nx">len</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="kd">var</span> <span class="nx">next</span> <span class="o">=</span> <span class="nx">accept</span><span class="p">[</span><span class="nx">nextIndex</span><span class="p">];</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">next</span> <span class="o">!==</span> <span class="s1">'string'</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nx">TypeError</span><span class="p">(</span><span class="s1">'accept must contains only string, given'</span> <span class="o">+</span> <span class="nx">next</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="nx">acceptList</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">next</span><span class="p">);</span>
|
||||
<span class="nx">nextIndex</span><span class="o">++</span><span class="p">;</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">}</span>
|
||||
|
||||
|
||||
<span class="kd">var</span> <span class="nx">notifier</span> <span class="o">=</span> <span class="nx">_getNotifier</span><span class="p">(</span><span class="nx">target</span><span class="p">),</span>
|
||||
<span class="nx">changeObservers</span> <span class="o">=</span> <span class="nx">changeObserversMap</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">notifier</span><span class="p">);</span>
|
||||
|
||||
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">l</span> <span class="o">=</span> <span class="nx">changeObservers</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">l</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="nx">changeObservers</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">callback</span> <span class="o">===</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="nx">changeObservers</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">accept</span> <span class="o">=</span> <span class="nx">acceptList</span><span class="p">;</span>
|
||||
<span class="k">return</span> <span class="nx">target</span><span class="p">;</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">}</span>
|
||||
|
||||
<span class="nx">changeObservers</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span>
|
||||
<span class="nx">callback</span><span class="o">:</span> <span class="nx">callback</span><span class="p">,</span>
|
||||
<span class="nx">accept</span><span class="o">:</span> <span class="nx">acceptList</span>
|
||||
<span class="p">});</span>
|
||||
|
||||
<span class="k">if</span> <span class="p">(</span><span class="nx">observerCallbacks</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">callback</span><span class="p">)</span> <span class="o">===</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="nx">observerCallbacks</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">callback</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">attachedNotifierCountMap</span><span class="p">.</span><span class="nx">has</span><span class="p">(</span><span class="nx">callback</span><span class="p">))</span> <span class="p">{</span>
|
||||
<span class="nx">attachedNotifierCountMap</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">callback</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
|
||||
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
|
||||
<span class="nx">attachedNotifierCountMap</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">callback</span><span class="p">,</span> <span class="nx">attachedNotifierCountMap</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">callback</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="k">return</span> <span class="nx">target</span><span class="p">;</span>
|
||||
<span class="p">},</span>
|
||||
<span class="nx">writable</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
|
||||
<span class="nx">configurable</span><span class="o">:</span> <span class="kc">true</span>
|
||||
<span class="p">},</span></pre></div> </td> </tr> <tr id="section-28"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-28">¶</a> </div> <p>Implementation of the public api 'Object.unobseve'
|
||||
described in the proposal.
|
||||
<a href="http://wiki.ecmascript.org/doku.php?id=harmony:observe_public_api#object.unobseve">Corresponding Section in ECMAScript wiki</a></p> </td> <td class="code"> <div class="highlight"><pre> <span class="s1">'unobserve'</span><span class="o">:</span> <span class="p">{</span>
|
||||
<span class="nx">value</span><span class="o">:</span> <span class="kd">function</span> <span class="nx">unobserve</span><span class="p">(</span><span class="nx">target</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="nb">Object</span><span class="p">(</span><span class="nx">target</span><span class="p">)</span> <span class="o">!==</span> <span class="nx">target</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nx">TypeError</span><span class="p">(</span><span class="s1">'target must be an Object, given '</span> <span class="o">+</span> <span class="nx">target</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">callback</span> <span class="o">!==</span> <span class="s1">'function'</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nx">TypeError</span><span class="p">(</span><span class="s1">'observer must be a function, given '</span> <span class="o">+</span> <span class="nx">callback</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="kd">var</span> <span class="nx">notifier</span> <span class="o">=</span> <span class="nx">_getNotifier</span><span class="p">(</span><span class="nx">target</span><span class="p">),</span>
|
||||
<span class="nx">changeObservers</span> <span class="o">=</span> <span class="nx">changeObserversMap</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">notifier</span><span class="p">);</span>
|
||||
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">l</span> <span class="o">=</span> <span class="nx">changeObservers</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">l</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="nx">changeObservers</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">callback</span> <span class="o">===</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="nx">changeObservers</span><span class="p">.</span><span class="nx">splice</span><span class="p">(</span><span class="nx">i</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
|
||||
<span class="nx">attachedNotifierCountMap</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">callback</span><span class="p">,</span> <span class="nx">attachedNotifierCountMap</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">callback</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">);</span>
|
||||
<span class="nx">_cleanObserver</span><span class="p">(</span><span class="nx">callback</span><span class="p">);</span>
|
||||
<span class="k">break</span><span class="p">;</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">}</span>
|
||||
<span class="k">return</span> <span class="nx">target</span><span class="p">;</span>
|
||||
<span class="p">},</span>
|
||||
<span class="nx">writable</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
|
||||
<span class="nx">configurable</span><span class="o">:</span> <span class="kc">true</span>
|
||||
<span class="p">},</span></pre></div> </td> </tr> <tr id="section-29"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-29">¶</a> </div> <p>Implementation of the public api 'Object.deliverChangeRecords'
|
||||
described in the proposal.
|
||||
<a href="http://wiki.ecmascript.org/doku.php?id=harmony:observe_public_api#object.deliverchangerecords">Corresponding Section in ECMAScript wiki</a></p> </td> <td class="code"> <div class="highlight"><pre> <span class="s1">'deliverChangeRecords'</span><span class="o">:</span> <span class="p">{</span>
|
||||
<span class="nx">value</span><span class="o">:</span> <span class="kd">function</span> <span class="nx">deliverChangeRecords</span><span class="p">(</span><span class="nx">observer</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">observer</span> <span class="o">!==</span> <span class="s1">'function'</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nx">TypeError</span><span class="p">(</span><span class="s1">'callback must be a function, given '</span> <span class="o">+</span> <span class="nx">observer</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="k">while</span> <span class="p">(</span><span class="nx">_deliverChangeRecords</span><span class="p">(</span><span class="nx">observer</span><span class="p">))</span> <span class="p">{}</span>
|
||||
<span class="p">},</span>
|
||||
<span class="nx">writable</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
|
||||
<span class="nx">configurable</span><span class="o">:</span> <span class="kc">true</span>
|
||||
<span class="p">},</span></pre></div> </td> </tr> <tr id="section-30"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-30">¶</a> </div> <p>Implementation of the public api 'Object.getNotifier'
|
||||
described in the proposal.
|
||||
<a href="http://wiki.ecmascript.org/doku.php?id=harmony:observe_public_api#object.getnotifier">Corresponding Section in ECMAScript wiki</a></p> </td> <td class="code"> <div class="highlight"><pre> <span class="s1">'getNotifier'</span><span class="o">:</span> <span class="p">{</span>
|
||||
<span class="nx">value</span><span class="o">:</span> <span class="kd">function</span> <span class="nx">getNotifier</span><span class="p">(</span><span class="nx">target</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="nb">Object</span><span class="p">(</span><span class="nx">target</span><span class="p">)</span> <span class="o">!==</span> <span class="nx">target</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nx">TypeError</span><span class="p">(</span><span class="s1">'target must be an Object, given '</span> <span class="o">+</span> <span class="nx">target</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="nb">Object</span><span class="p">.</span><span class="nx">isFrozen</span><span class="p">(</span><span class="nx">target</span><span class="p">))</span> <span class="p">{</span>
|
||||
<span class="k">return</span> <span class="kc">null</span><span class="p">;</span>
|
||||
<span class="p">}</span>
|
||||
<span class="k">return</span> <span class="nx">_getNotifier</span><span class="p">(</span><span class="nx">target</span><span class="p">);</span>
|
||||
<span class="p">},</span>
|
||||
<span class="nx">writable</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
|
||||
<span class="nx">configurable</span><span class="o">:</span> <span class="kc">true</span>
|
||||
<span class="p">}</span>
|
||||
|
||||
<span class="p">});</span>
|
||||
|
||||
<span class="p">})(</span><span class="k">typeof</span> <span class="nx">global</span> <span class="o">!==</span> <span class="s1">'undefined'</span> <span class="o">?</span> <span class="nx">global</span> <span class="o">:</span> <span class="k">this</span><span class="p">);</span>
|
||||
|
||||
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
|
519
bower_components/observe-shim/lib/observe-shim.js
vendored
Normal file
519
bower_components/observe-shim/lib/observe-shim.js
vendored
Normal file
@ -0,0 +1,519 @@
|
||||
// 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/),
|
||||
|
||||
// Object.observe Shim
|
||||
// ===================
|
||||
|
||||
// *See [The harmony proposal page](http://wiki.ecmascript.org/doku.php?id=harmony:observe)*
|
||||
|
||||
(function (global) {
|
||||
'use strict';
|
||||
if (typeof Object.observe === 'function') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Utilities
|
||||
// ---------
|
||||
|
||||
// setImmediate shim used to deliver changes records asynchronously
|
||||
// use setImmediate if available
|
||||
var setImmediate = global.setImmediate || global.msSetImmediate,
|
||||
clearImmediate = global.clearImmediate || global.msClearImmediate;
|
||||
if (!setImmediate) {
|
||||
// fallback on setTimeout if not
|
||||
setImmediate = function (func, args) {
|
||||
return setTimeout(func, 0, args);
|
||||
};
|
||||
clearImmediate = function (id) {
|
||||
clearTimeout(id);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// WeakMap
|
||||
// -------
|
||||
|
||||
var PrivateMap;
|
||||
if (typeof WeakMap !== 'undefined') {
|
||||
//use weakmap if defined
|
||||
PrivateMap = WeakMap;
|
||||
} else {
|
||||
//else use ses like shim of WeakMap
|
||||
var HIDDEN_PREFIX = '__weakmap:' + (Math.random() * 1e9 >>> 0),
|
||||
counter = new Date().getTime() % 1e9,
|
||||
mascot = {};
|
||||
|
||||
PrivateMap = function () {
|
||||
this.name = HIDDEN_PREFIX + (Math.random() * 1e9 >>> 0) + (counter++ + '__');
|
||||
};
|
||||
|
||||
PrivateMap.prototype = {
|
||||
has: function (key) {
|
||||
return key && key.hasOwnProperty(this.name);
|
||||
},
|
||||
|
||||
get: function (key) {
|
||||
var value = key && key[this.name];
|
||||
return value === mascot ? undefined : value;
|
||||
},
|
||||
|
||||
set: function (key, value) {
|
||||
Object.defineProperty(key, this.name, {
|
||||
value : typeof value === 'undefined' ? mascot : value,
|
||||
enumerable: false,
|
||||
writable : true,
|
||||
configurable: true
|
||||
});
|
||||
},
|
||||
|
||||
'delete': function (key) {
|
||||
return delete key[this.name];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var getOwnPropertyName = Object.getOwnPropertyNames;
|
||||
Object.defineProperty(Object, 'getOwnPropertyNames', {
|
||||
value: function fakeGetOwnPropertyNames(obj) {
|
||||
return getOwnPropertyName(obj).filter(function (name) {
|
||||
return name.substr(0, HIDDEN_PREFIX.length) !== HIDDEN_PREFIX;
|
||||
});
|
||||
},
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Internal Properties
|
||||
// -------------------
|
||||
|
||||
// An ordered list used to provide a deterministic ordering in which callbacks are called.
|
||||
// [Corresponding Section in ECMAScript wiki](http://wiki.ecmascript.org/doku.php?id=harmony:observe_internals#observercallbacks)
|
||||
var observerCallbacks = [];
|
||||
|
||||
// This object is used as the prototype of all the notifiers that are returned by Object.getNotifier(O).
|
||||
// [Corresponding Section in ECMAScript wiki](http://wiki.ecmascript.org/doku.php?id=harmony:observe_internals#notifierprototype)
|
||||
var NotifierPrototype = Object.create(Object.prototype);
|
||||
|
||||
// Used to store immediate uid reference
|
||||
var changeDeliveryImmediateUid;
|
||||
|
||||
// Used to schedule a call to _deliverAllChangeRecords
|
||||
function setUpChangesDelivery() {
|
||||
clearImmediate(changeDeliveryImmediateUid);
|
||||
changeDeliveryImmediateUid = setImmediate(_deliverAllChangeRecords);
|
||||
}
|
||||
|
||||
Object.defineProperty(NotifierPrototype, 'notify', {
|
||||
value: function notify(changeRecord) {
|
||||
var notifier = this;
|
||||
if (Object(notifier) !== notifier) {
|
||||
throw new TypeError('this must be an Object, given ' + notifier);
|
||||
}
|
||||
if (!notifier.__target) {
|
||||
return;
|
||||
}
|
||||
if (Object(changeRecord) !== changeRecord) {
|
||||
throw new TypeError('changeRecord must be an Object, given ' + changeRecord);
|
||||
}
|
||||
|
||||
|
||||
var type = changeRecord.type;
|
||||
if (typeof type !== 'string') {
|
||||
throw new TypeError('changeRecord.type must be a string, given ' + type);
|
||||
}
|
||||
|
||||
var changeObservers = changeObserversMap.get(notifier);
|
||||
if (!changeObservers || changeObservers.length === 0) {
|
||||
return;
|
||||
}
|
||||
var target = notifier.__target,
|
||||
newRecord = Object.create(Object.prototype, {
|
||||
'object': {
|
||||
value: target,
|
||||
writable : false,
|
||||
enumerable : true,
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
for (var prop in changeRecord) {
|
||||
if (prop !== 'object') {
|
||||
var value = changeRecord[prop];
|
||||
Object.defineProperty(newRecord, prop, {
|
||||
value: value,
|
||||
writable : false,
|
||||
enumerable : true,
|
||||
configurable: false
|
||||
});
|
||||
}
|
||||
}
|
||||
Object.preventExtensions(newRecord);
|
||||
_enqueueChangeRecord(notifier.__target, newRecord);
|
||||
},
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable : true
|
||||
});
|
||||
|
||||
Object.defineProperty(NotifierPrototype, 'performChange', {
|
||||
value: function performChange(changeType, changeFn) {
|
||||
var notifier = this;
|
||||
if (Object(notifier) !== notifier) {
|
||||
throw new TypeError('this must be an Object, given ' + notifier);
|
||||
}
|
||||
if (!notifier.__target) {
|
||||
return;
|
||||
}
|
||||
if (typeof changeType !== 'string') {
|
||||
throw new TypeError('changeType must be a string given ' + notifier);
|
||||
}
|
||||
if (typeof changeFn !== 'function') {
|
||||
throw new TypeError('changeFn must be a function, given ' + changeFn);
|
||||
}
|
||||
|
||||
_beginChange(notifier.__target, changeType);
|
||||
var error, changeRecord;
|
||||
try {
|
||||
changeRecord = changeFn.call(undefined);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
_endChange(notifier.__target, changeType);
|
||||
if (typeof error !== 'undefined') {
|
||||
throw error;
|
||||
}
|
||||
|
||||
var changeObservers = changeObserversMap.get(notifier);
|
||||
if (changeObservers.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
var target = notifier.__target,
|
||||
newRecord = Object.create(Object.prototype, {
|
||||
'object': {
|
||||
value: target,
|
||||
writable : false,
|
||||
enumerable : true,
|
||||
configurable: false
|
||||
},
|
||||
'type': {
|
||||
value: changeType,
|
||||
writable : false,
|
||||
enumerable : true,
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
if (typeof changeRecord !== 'undefined') {
|
||||
for (var prop in changeRecord) {
|
||||
if (prop !== 'object' && prop !== 'type') {
|
||||
var value = changeRecord[prop];
|
||||
Object.defineProperty(newRecord, prop, {
|
||||
value: value,
|
||||
writable : false,
|
||||
enumerable : true,
|
||||
configurable: false
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Object.preventExtensions(newRecord);
|
||||
_enqueueChangeRecord(notifier.__target, newRecord);
|
||||
|
||||
},
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable : true
|
||||
});
|
||||
|
||||
// Implementation of the internal algorithm 'BeginChange'
|
||||
// described in the proposal.
|
||||
// [Corresponding Section in ECMAScript wiki](http://wiki.ecmascript.org/doku.php?id=harmony:observe_internals#beginchange)
|
||||
function _beginChange(object, changeType) {
|
||||
var notifier = Object.getNotifier(object),
|
||||
activeChanges = activeChangesMap.get(notifier),
|
||||
changeCount = activeChangesMap.get(notifier)[changeType];
|
||||
activeChanges[changeType] = typeof changeCount === 'undefined' ? 1 : changeCount + 1;
|
||||
}
|
||||
|
||||
// Implementation of the internal algorithm 'EndChange'
|
||||
// described in the proposal.
|
||||
// [Corresponding Section in ECMAScript wiki](http://wiki.ecmascript.org/doku.php?id=harmony:observe_internals#endchange)
|
||||
function _endChange(object, changeType) {
|
||||
var notifier = Object.getNotifier(object),
|
||||
activeChanges = activeChangesMap.get(notifier),
|
||||
changeCount = activeChangesMap.get(notifier)[changeType];
|
||||
activeChanges[changeType] = changeCount > 0 ? changeCount - 1 : 0;
|
||||
}
|
||||
|
||||
// Implementation of the internal algorithm 'ShouldDeliverToObserver'
|
||||
// described in the proposal.
|
||||
// [Corresponding Section in ECMAScript wiki](http://wiki.ecmascript.org/doku.php?id=harmony:observe_internals#shoulddelivertoobserver)
|
||||
function _shouldDeliverToObserver(activeChanges, acceptList, changeType) {
|
||||
var doesAccept = false;
|
||||
if (acceptList) {
|
||||
for (var i = 0, l = acceptList.length; i < l; i++) {
|
||||
var accept = acceptList[i];
|
||||
if (activeChanges[accept] > 0) {
|
||||
return false;
|
||||
}
|
||||
if (accept === changeType) {
|
||||
doesAccept = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return doesAccept;
|
||||
}
|
||||
|
||||
|
||||
// Map used to store corresponding notifier to an object
|
||||
var notifierMap = new PrivateMap(),
|
||||
changeObserversMap = new PrivateMap(),
|
||||
activeChangesMap = new PrivateMap();
|
||||
|
||||
// Implementation of the internal algorithm 'GetNotifier'
|
||||
// described in the proposal.
|
||||
// [Corresponding Section in ECMAScript wiki](http://wiki.ecmascript.org/doku.php?id=harmony:observe_internals#getnotifier)
|
||||
function _getNotifier(target) {
|
||||
if (!notifierMap.has(target)) {
|
||||
var notifier = Object.create(NotifierPrototype);
|
||||
// we does not really need to hide this, since anyway the host object is accessible from outside of the
|
||||
// implementation. we just make it unwritable
|
||||
Object.defineProperty(notifier, '__target', { value : target });
|
||||
changeObserversMap.set(notifier, []);
|
||||
activeChangesMap.set(notifier, {});
|
||||
notifierMap.set(target, notifier);
|
||||
}
|
||||
return notifierMap.get(target);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// map used to store reference to a list of pending changeRecords
|
||||
// in observer callback.
|
||||
var pendingChangesMap = new PrivateMap();
|
||||
|
||||
// Implementation of the internal algorithm 'EnqueueChangeRecord'
|
||||
// described in the proposal.
|
||||
// [Corresponding Section in ECMAScript wiki](http://wiki.ecmascript.org/doku.php?id=harmony:observe_internals#enqueuechangerecord)
|
||||
function _enqueueChangeRecord(object, changeRecord) {
|
||||
var notifier = Object.getNotifier(object),
|
||||
changeType = changeRecord.type,
|
||||
activeChanges = activeChangesMap.get(notifier),
|
||||
changeObservers = changeObserversMap.get(notifier);
|
||||
|
||||
for (var i = 0, l = changeObservers.length; i < l; i++) {
|
||||
var observerRecord = changeObservers[i],
|
||||
acceptList = observerRecord.accept;
|
||||
if (_shouldDeliverToObserver(activeChanges, acceptList, changeType)) {
|
||||
var observer = observerRecord.callback,
|
||||
pendingChangeRecords = [];
|
||||
if (!pendingChangesMap.has(observer)) {
|
||||
pendingChangesMap.set(observer, pendingChangeRecords);
|
||||
} else {
|
||||
pendingChangeRecords = pendingChangesMap.get(observer);
|
||||
}
|
||||
pendingChangeRecords.push(changeRecord);
|
||||
}
|
||||
}
|
||||
setUpChangesDelivery();
|
||||
}
|
||||
|
||||
// map used to store a count of associated notifier to a function
|
||||
var attachedNotifierCountMap = new PrivateMap();
|
||||
|
||||
// Remove reference all reference to an observer callback,
|
||||
// if this one is not used anymore.
|
||||
// In the proposal the ObserverCallBack has a weak reference over observers,
|
||||
// Without this possibility we need to clean this list to avoid memory leak
|
||||
function _cleanObserver(observer) {
|
||||
if (!attachedNotifierCountMap.get(observer) && !pendingChangesMap.has(observer)) {
|
||||
attachedNotifierCountMap.delete(observer);
|
||||
var index = observerCallbacks.indexOf(observer);
|
||||
if (index !== -1) {
|
||||
observerCallbacks.splice(index, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Implementation of the internal algorithm 'DeliverChangeRecords'
|
||||
// described in the proposal.
|
||||
// [Corresponding Section in ECMAScript wiki](http://wiki.ecmascript.org/doku.php?id=harmony:observe_internals#deliverchangerecords)
|
||||
function _deliverChangeRecords(observer) {
|
||||
var pendingChangeRecords = pendingChangesMap.get(observer);
|
||||
pendingChangesMap.delete(observer);
|
||||
if (!pendingChangeRecords || pendingChangeRecords.length === 0) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
observer.call(undefined, pendingChangeRecords);
|
||||
}
|
||||
catch (e) { }
|
||||
|
||||
_cleanObserver(observer);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Implementation of the internal algorithm 'DeliverAllChangeRecords'
|
||||
// described in the proposal.
|
||||
// [Corresponding Section in ECMAScript wiki](http://wiki.ecmascript.org/doku.php?id=harmony:observe_internals#deliverallchangerecords)
|
||||
function _deliverAllChangeRecords() {
|
||||
var observers = observerCallbacks.slice();
|
||||
var anyWorkDone = false;
|
||||
for (var i = 0, l = observers.length; i < l; i++) {
|
||||
var observer = observers[i];
|
||||
if (_deliverChangeRecords(observer)) {
|
||||
anyWorkDone = true;
|
||||
}
|
||||
}
|
||||
return anyWorkDone;
|
||||
}
|
||||
|
||||
|
||||
Object.defineProperties(Object, {
|
||||
// Implementation of the public api 'Object.observe'
|
||||
// described in the proposal.
|
||||
// [Corresponding Section in ECMAScript wiki](http://wiki.ecmascript.org/doku.php?id=harmony:observe_public_api#object.observe)
|
||||
'observe': {
|
||||
value: function observe(target, callback, accept) {
|
||||
if (Object(target) !== target) {
|
||||
throw new TypeError('target must be an Object, given ' + target);
|
||||
}
|
||||
if (typeof callback !== 'function') {
|
||||
throw new TypeError('observer must be a function, given ' + callback);
|
||||
}
|
||||
if (Object.isFrozen(callback)) {
|
||||
throw new TypeError('observer cannot be frozen');
|
||||
}
|
||||
|
||||
var acceptList;
|
||||
if (typeof accept === 'undefined') {
|
||||
acceptList = ['add', 'update', 'delete', 'reconfigure', 'setPrototype', 'preventExtensions'];
|
||||
} else {
|
||||
if (Object(accept) !== accept) {
|
||||
throw new TypeError('accept must be an object, given ' + accept);
|
||||
}
|
||||
var len = accept.length;
|
||||
if (typeof len !== 'number' || len >>> 0 !== len || len < 1) {
|
||||
throw new TypeError('the \'length\' property of accept must be a positive integer, given ' + len);
|
||||
}
|
||||
|
||||
var nextIndex = 0;
|
||||
acceptList = [];
|
||||
while (nextIndex < len) {
|
||||
var next = accept[nextIndex];
|
||||
if (typeof next !== 'string') {
|
||||
throw new TypeError('accept must contains only string, given' + next);
|
||||
}
|
||||
acceptList.push(next);
|
||||
nextIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var notifier = _getNotifier(target),
|
||||
changeObservers = changeObserversMap.get(notifier);
|
||||
|
||||
for (var i = 0, l = changeObservers.length; i < l; i++) {
|
||||
if (changeObservers[i].callback === callback) {
|
||||
changeObservers[i].accept = acceptList;
|
||||
return target;
|
||||
}
|
||||
}
|
||||
|
||||
changeObservers.push({
|
||||
callback: callback,
|
||||
accept: acceptList
|
||||
});
|
||||
|
||||
if (observerCallbacks.indexOf(callback) === -1) {
|
||||
observerCallbacks.push(callback);
|
||||
}
|
||||
if (!attachedNotifierCountMap.has(callback)) {
|
||||
attachedNotifierCountMap.set(callback, 1);
|
||||
} else {
|
||||
attachedNotifierCountMap.set(callback, attachedNotifierCountMap.get(callback) + 1);
|
||||
}
|
||||
return target;
|
||||
},
|
||||
writable: true,
|
||||
configurable: true
|
||||
},
|
||||
|
||||
// Implementation of the public api 'Object.unobseve'
|
||||
// described in the proposal.
|
||||
// [Corresponding Section in ECMAScript wiki](http://wiki.ecmascript.org/doku.php?id=harmony:observe_public_api#object.unobseve)
|
||||
'unobserve': {
|
||||
value: function unobserve(target, callback) {
|
||||
if (Object(target) !== target) {
|
||||
throw new TypeError('target must be an Object, given ' + target);
|
||||
}
|
||||
if (typeof callback !== 'function') {
|
||||
throw new TypeError('observer must be a function, given ' + callback);
|
||||
}
|
||||
var notifier = _getNotifier(target),
|
||||
changeObservers = changeObserversMap.get(notifier);
|
||||
for (var i = 0, l = changeObservers.length; i < l; i++) {
|
||||
if (changeObservers[i].callback === callback) {
|
||||
changeObservers.splice(i, 1);
|
||||
attachedNotifierCountMap.set(callback, attachedNotifierCountMap.get(callback) - 1);
|
||||
_cleanObserver(callback);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return target;
|
||||
},
|
||||
writable: true,
|
||||
configurable: true
|
||||
},
|
||||
|
||||
// Implementation of the public api 'Object.deliverChangeRecords'
|
||||
// described in the proposal.
|
||||
// [Corresponding Section in ECMAScript wiki](http://wiki.ecmascript.org/doku.php?id=harmony:observe_public_api#object.deliverchangerecords)
|
||||
'deliverChangeRecords': {
|
||||
value: function deliverChangeRecords(observer) {
|
||||
if (typeof observer !== 'function') {
|
||||
throw new TypeError('callback must be a function, given ' + observer);
|
||||
}
|
||||
while (_deliverChangeRecords(observer)) {}
|
||||
},
|
||||
writable: true,
|
||||
configurable: true
|
||||
},
|
||||
|
||||
// Implementation of the public api 'Object.getNotifier'
|
||||
// described in the proposal.
|
||||
// [Corresponding Section in ECMAScript wiki](http://wiki.ecmascript.org/doku.php?id=harmony:observe_public_api#object.getnotifier)
|
||||
'getNotifier': {
|
||||
value: function getNotifier(target) {
|
||||
if (Object(target) !== target) {
|
||||
throw new TypeError('target must be an Object, given ' + target);
|
||||
}
|
||||
if (Object.isFrozen(target)) {
|
||||
return null;
|
||||
}
|
||||
return _getNotifier(target);
|
||||
},
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
})(typeof global !== 'undefined' ? global : this);
|
||||
|
||||
|
46
bower_components/observe-shim/package.json
vendored
Normal file
46
bower_components/observe-shim/package.json
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
{
|
||||
"name": "observe-shim",
|
||||
"description": "An Object.observe harmony proposal shim",
|
||||
"version": "0.4.2",
|
||||
"keywords": [
|
||||
"observe",
|
||||
"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-shim.git"
|
||||
},
|
||||
"main": "lib/observe-shim.js",
|
||||
"scripts": {
|
||||
"test": "grunt test"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"matchdep": "~0.1.1",
|
||||
"grunt": "~0.4.0",
|
||||
"grunt-contrib-jshint": "~0.1.1",
|
||||
"grunt-mocha": "~0.4.1",
|
||||
"grunt-docco": "~0.2.0",
|
||||
"grunt-contrib-clean": "~0.4.0",
|
||||
"mocha": "~1.12.0",
|
||||
"sinon": "~1.7.3",
|
||||
"expect.js": "~0.2.0",
|
||||
"grunt-mocha-test": "~0.5.0"
|
||||
},
|
||||
"licenses": {
|
||||
"type": "Apache-2.0",
|
||||
"url": "http://www.apache.org/licenses/LICENSE-2.0"
|
||||
}
|
||||
}
|
563
bower_components/observe-shim/test/Object.observe.js
vendored
Normal file
563
bower_components/observe-shim/test/Object.observe.js
vendored
Normal file
@ -0,0 +1,563 @@
|
||||
// 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, expect , beforeEach, afterEach, sinon*/
|
||||
|
||||
describe('Observe.observe harmony proposal shim', function () {
|
||||
'use strict';
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
function testIsCallable(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.throwException(function (e) {
|
||||
expect(e).to.be.a(TypeError);
|
||||
});
|
||||
|
||||
expect(function () {
|
||||
//tricks for jshint
|
||||
var Fn = Function;
|
||||
testFunc(new Fn(''));
|
||||
}).to.not.throwException();
|
||||
|
||||
expect(function () {
|
||||
testFunc(function () {});
|
||||
}).to.not.throwException();
|
||||
}
|
||||
|
||||
describe('Object.observe', function () {
|
||||
it('should throw an error when passing an non object at first parameter', function () {
|
||||
testIsObject(function (target) {
|
||||
Object.observe(target, function () { });
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw an error when second parameter is not callable', function () {
|
||||
testIsCallable(function (observer) {
|
||||
Object.observe({}, observer);
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw an error when second parameter is frozen', function () {
|
||||
var observer = function () { };
|
||||
Object.freeze(observer);
|
||||
expect(function () {
|
||||
Object.observe({}, observer);
|
||||
}).to.throwException(function (e) {
|
||||
expect(e).to.be.a(TypeError);
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw an error when third parameter is defined and is not an array like of string', function () {
|
||||
expect(function () {
|
||||
Object.observe({}, function () {}, {});
|
||||
}).to.throwException(function (e) {
|
||||
expect(e).to.be.a(TypeError);
|
||||
});
|
||||
|
||||
expect(function () {
|
||||
Object.observe({}, function () {}, [5, {}]);
|
||||
}).to.throwException(function (e) {
|
||||
expect(e).to.be.a(TypeError);
|
||||
});
|
||||
|
||||
expect(function () {
|
||||
Object.observe({}, function () {}, ['hello', '']);
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Object.unobserve', function () {
|
||||
it('should throw an error when passing an non object at first parameter', function () {
|
||||
testIsObject(function (target) {
|
||||
Object.unobserve(target, function () { });
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw an error when second parameter is not callable', function () {
|
||||
testIsCallable(function (observer) {
|
||||
Object.unobserve({}, observer);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
describe('Object.getNotifier', function () {
|
||||
it('should throw an error when passing an non object at first parameter', function () {
|
||||
testIsObject(function (target) {
|
||||
Object.getNotifier(target);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
it('should return a notifier with a "notify" function, configurable, writable and not enumerable', function () {
|
||||
var notifier = Object.getNotifier({}),
|
||||
notifyDesc = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(notifier), 'notify');
|
||||
|
||||
expect(notifyDesc).to.be.ok();
|
||||
expect(notifyDesc.value).to.be.a('function');
|
||||
expect(notifyDesc.configurable).to.be.ok();
|
||||
expect(notifyDesc.writable).to.be.ok();
|
||||
expect(notifyDesc.enumerable).not.to.be.ok();
|
||||
});
|
||||
|
||||
|
||||
it('should return a unique notifier for a given object', function () {
|
||||
var obj = {},
|
||||
notifier = Object.getNotifier(obj),
|
||||
notifier1 = Object.getNotifier(obj);
|
||||
|
||||
expect(notifier).to.be.equal(notifier1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Object.deliverChangeRecords', function () {
|
||||
it('should throw an error when passing an non object at first parameter', function () {
|
||||
testIsCallable(function (observer) {
|
||||
Object.deliverChangeRecords(observer);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('Notifier.notify', function () {
|
||||
|
||||
var notifier = Object.getNotifier({});
|
||||
|
||||
it('should throw an error when passing an non-object as parameter', function () {
|
||||
expect(function () {
|
||||
notifier.notify(5);
|
||||
}).to.throwException(function (e) {
|
||||
expect(e).to.be.a(TypeError);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should throw an error when the property type of the first parameter is not a string', function () {
|
||||
expect(function () {
|
||||
notifier.notify({ type: 4 });
|
||||
}).to.throwException(function (e) {
|
||||
expect(e).to.be.a(TypeError);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('Notifier.performChange', function () {
|
||||
|
||||
var notifier = Object.getNotifier({});
|
||||
|
||||
it('should throw an error when passing a non string as first parameter', function () {
|
||||
expect(function () {
|
||||
notifier.performChange(null, function () {});
|
||||
}).to.throwException(function (e) {
|
||||
expect(e).to.be.a(TypeError);
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw an error when second parameter is not callable', function () {
|
||||
testIsCallable(function (observer) {
|
||||
notifier.performChange('update', observer);
|
||||
});
|
||||
});
|
||||
|
||||
it('should call the changeFunction', function () {
|
||||
var spy = sinon.spy();
|
||||
notifier.performChange('update', spy);
|
||||
expect(spy.calledOnce).to.be.ok();
|
||||
});
|
||||
|
||||
|
||||
it('should rethrow any error thrown by the changeFunction', function () {
|
||||
expect(function () {
|
||||
notifier.performChange('update', function () {
|
||||
throw new RangeError('changeFunction exception');
|
||||
});
|
||||
}).to.throwException(function (e) {
|
||||
expect(e).to.be.a(RangeError);
|
||||
expect(e.message).to.be('changeFunction exception');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Changes delivery', function () {
|
||||
var obj, notifier, observer;
|
||||
|
||||
beforeEach(function () {
|
||||
obj = {};
|
||||
observer = sinon.spy();
|
||||
Object.observe(obj, observer);
|
||||
notifier = Object.getNotifier(obj);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
Object.unobserve(obj, observer);
|
||||
obj = observer = notifier = null;
|
||||
});
|
||||
|
||||
|
||||
function getDeliveredRecords() {
|
||||
return observer.args[0][0];
|
||||
}
|
||||
|
||||
|
||||
it('should call the observer when a change record is delivered', function () {
|
||||
notifier.notify({
|
||||
type: 'update',
|
||||
name: 'foo'
|
||||
});
|
||||
|
||||
Object.deliverChangeRecords(observer);
|
||||
expect(observer.calledOnce).to.be.ok();
|
||||
});
|
||||
|
||||
|
||||
it('should call the observer only one time when multiples changes records are delivered', function () {
|
||||
notifier.notify({
|
||||
type: 'update',
|
||||
name: 'foo'
|
||||
});
|
||||
notifier.notify({
|
||||
type: 'update',
|
||||
name: 'foo'
|
||||
});
|
||||
|
||||
Object.deliverChangeRecords(observer);
|
||||
expect(observer.calledOnce).to.be.ok();
|
||||
});
|
||||
|
||||
|
||||
it('should call the observer only one time when multiples changes records are delivered', function () {
|
||||
notifier.notify({
|
||||
type: 'update'
|
||||
});
|
||||
notifier.notify({
|
||||
type: 'update'
|
||||
});
|
||||
|
||||
Object.deliverChangeRecords(observer);
|
||||
expect(observer.calledOnce).to.be.ok();
|
||||
});
|
||||
|
||||
|
||||
it('should deliver a change record with a property "object" corresponding to the observed object', function () {
|
||||
notifier.notify({
|
||||
type: 'update'
|
||||
});
|
||||
Object.deliverChangeRecords(observer);
|
||||
var deliveredRecord = getDeliveredRecords()[0];
|
||||
expect(deliveredRecord).to.have.property('object', obj);
|
||||
});
|
||||
|
||||
it('should ignore an object property specified in the original change record', function () {
|
||||
notifier.notify({
|
||||
type: 'update',
|
||||
object : 'foo'
|
||||
});
|
||||
Object.deliverChangeRecords(observer);
|
||||
var deliveredRecord = getDeliveredRecords()[0];
|
||||
expect(deliveredRecord).to.have.property('object', obj);
|
||||
});
|
||||
|
||||
it('should deliver a change record with all other property equals to the original one', function () {
|
||||
notifier.notify({
|
||||
type: 'update',
|
||||
foo : 1,
|
||||
bar : 2
|
||||
});
|
||||
Object.deliverChangeRecords(observer);
|
||||
var deliveredRecord = getDeliveredRecords()[0];
|
||||
expect(deliveredRecord).to.have.property('foo', 1);
|
||||
expect(deliveredRecord).to.have.property('bar', 2);
|
||||
});
|
||||
|
||||
it('should call the observer function only once even in case of multiple observation', function () {
|
||||
Object.observe(obj, observer);
|
||||
notifier.notify({
|
||||
type: 'update',
|
||||
name: 'foo'
|
||||
});
|
||||
|
||||
Object.deliverChangeRecords(observer);
|
||||
expect(observer.calledOnce).to.be.ok();
|
||||
});
|
||||
|
||||
it('should not call a function that has not been used for an observation', function () {
|
||||
var observer2 = sinon.spy();
|
||||
notifier.notify({
|
||||
type: 'update',
|
||||
name: 'foo'
|
||||
});
|
||||
Object.deliverChangeRecords(observer2);
|
||||
expect(observer2.called).not.to.be.ok();
|
||||
});
|
||||
|
||||
it('should not call the observer after call to Object.unobserve', function () {
|
||||
Object.unobserve(obj, observer);
|
||||
notifier.notify({
|
||||
type: 'update',
|
||||
name: 'foo'
|
||||
});
|
||||
Object.deliverChangeRecords(observer);
|
||||
expect(observer.called).not.to.be.ok();
|
||||
});
|
||||
|
||||
it('should not deliver change records between an unobservation and a reobservation', function () {
|
||||
Object.unobserve(obj, observer);
|
||||
notifier.notify({
|
||||
type: 'update',
|
||||
name: 'foo'
|
||||
});
|
||||
Object.observe(obj, observer);
|
||||
notifier.notify({
|
||||
type: 'update',
|
||||
name: 'foo'
|
||||
});
|
||||
Object.deliverChangeRecords(observer);
|
||||
expect(getDeliveredRecords()).to.have.length(1);
|
||||
});
|
||||
|
||||
|
||||
it('should deliver records in the order of notification', function () {
|
||||
notifier.notify({
|
||||
type: 'update',
|
||||
order: 0
|
||||
});
|
||||
|
||||
notifier.notify({
|
||||
type: 'update',
|
||||
order: 1
|
||||
});
|
||||
|
||||
notifier.notify({
|
||||
type: 'update',
|
||||
order: 2
|
||||
});
|
||||
|
||||
Object.deliverChangeRecords(observer);
|
||||
|
||||
var changeRecords = getDeliveredRecords();
|
||||
expect(changeRecords[0]).to.have.property('order', 0);
|
||||
expect(changeRecords[1]).to.have.property('order', 1);
|
||||
expect(changeRecords[2]).to.have.property('order', 2);
|
||||
});
|
||||
|
||||
|
||||
it('should deliver change records asynchronously without a call to Object.deliverChangeRecords', function (done) {
|
||||
this.timeout(100);
|
||||
Object.observe(obj, function () {
|
||||
done();
|
||||
});
|
||||
notifier.notify({
|
||||
type: 'update'
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should deliver change records in the order of observation', function (done) {
|
||||
this.timeout(100);
|
||||
var obj2 = {},
|
||||
notifier2 = Object.getNotifier(obj2),
|
||||
observer2 = sinon.spy(function () {
|
||||
expect(observer.called).to.be.ok();
|
||||
});
|
||||
|
||||
Object.observe(obj2, observer2);
|
||||
|
||||
Object.observe(obj, function () {
|
||||
expect(observer2.called).to.be.ok();
|
||||
done();
|
||||
});
|
||||
|
||||
notifier.notify({
|
||||
type: 'update'
|
||||
});
|
||||
|
||||
notifier2.notify({
|
||||
type: 'update'
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should only deliver change records with type in the accept list if defined', function () {
|
||||
Object.observe(obj, observer, ['bar', 'foo']);
|
||||
|
||||
notifier.notify({
|
||||
type: 'update'
|
||||
});
|
||||
|
||||
notifier.notify({
|
||||
type: 'foo'
|
||||
});
|
||||
|
||||
notifier.notify({
|
||||
type: 'new'
|
||||
});
|
||||
|
||||
notifier.notify({
|
||||
type: 'foo'
|
||||
});
|
||||
|
||||
notifier.notify({
|
||||
type: 'bar'
|
||||
});
|
||||
|
||||
Object.deliverChangeRecords(observer);
|
||||
|
||||
expect(getDeliveredRecords()).to.be.eql([
|
||||
{ object : obj, type: 'foo' },
|
||||
{ object : obj, type: 'foo' },
|
||||
{ object : obj, type: 'bar' }
|
||||
]);
|
||||
});
|
||||
|
||||
it('should deliver a change record with \'type\' property equals to the performChange \'changeType\' ' +
|
||||
'argument value and with properties of the returned value of the changeFunction', function () {
|
||||
notifier.performChange('update', function () { });
|
||||
notifier.performChange('delete', function () {
|
||||
return {
|
||||
message: 'hello world'
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
Object.deliverChangeRecords(observer);
|
||||
|
||||
expect(getDeliveredRecords()).to.be.eql([
|
||||
{ object : obj, type: 'update' },
|
||||
{ object : obj, type: 'delete', message: 'hello world' }
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
it('should only deliver first changeType passed to performChange if part of accept list during a performChange', function () {
|
||||
var notifyFoo = function () {
|
||||
notifier.performChange('foo', function () {
|
||||
notifier.notify({type : 'reconfigure'});
|
||||
});
|
||||
|
||||
}, notifyBar = function () {
|
||||
notifier.performChange('bar', function () {
|
||||
notifier.notify({type : 'setPrototype'});
|
||||
});
|
||||
}, notifyFooAndBar = function () {
|
||||
notifier.performChange('fooAndBar', function () {
|
||||
notifyFoo();
|
||||
notifyBar();
|
||||
});
|
||||
}, observer2 = sinon.spy();
|
||||
|
||||
Object.observe(obj, observer2, ['foo', 'bar', 'fooAndBar']);
|
||||
|
||||
notifyFoo();
|
||||
notifyBar();
|
||||
notifyFooAndBar();
|
||||
Object.deliverChangeRecords(observer);
|
||||
Object.deliverChangeRecords(observer2);
|
||||
|
||||
expect(getDeliveredRecords()).to.be.eql([
|
||||
{ object : obj, type: 'reconfigure' },
|
||||
{ object : obj, type: 'setPrototype' },
|
||||
{ object : obj, type: 'reconfigure' },
|
||||
{ object : obj, type: 'setPrototype' }
|
||||
]);
|
||||
|
||||
expect(observer2.args[0][0]).to.be.eql([
|
||||
{ object : obj, type: 'foo' },
|
||||
{ object : obj, type: 'bar' },
|
||||
{ object : obj, type: 'fooAndBar' }
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
});
|
30
bower_components/observe-shim/test/bugs.js
vendored
Normal file
30
bower_components/observe-shim/test/bugs.js
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
// 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 */
|
||||
|
||||
|
||||
describe('observer shim bugs', function () {
|
||||
'use strict';
|
||||
it('unobserving when there is 2 observer attached to an object, and pending changes records cause an error', function () {
|
||||
var obj = {}, observer = function () {}, observer1 = function () {};
|
||||
Object.observe(obj, observer);
|
||||
Object.observe(obj, observer1);
|
||||
|
||||
Object.getNotifier(obj).notify({type : 'updated'});
|
||||
|
||||
Object.unobserve(obj, observer);
|
||||
});
|
||||
});
|
27
bower_components/observe-shim/test/index.html
vendored
Normal file
27
bower_components/observe-shim/test/index.html
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!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="../lib/observe-shim.js" ></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha"></div>
|
||||
<script type="text/javascript">
|
||||
mocha.setup("bdd");
|
||||
</script>
|
||||
<script src="./Object.observe.js" type="text/javascript" ></script>
|
||||
<script src="./bugs.js" type="text/javascript"></script>
|
||||
<script type="text/javascript" >
|
||||
if ( typeof window.PHANTOMJS === "undefined") {
|
||||
mocha.run();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
7
bower_components/observe-shim/test/node-index.js
vendored
Normal file
7
bower_components/observe-shim/test/node-index.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
// exported expect, sinon
|
||||
|
||||
global.expect = require('expect.js');
|
||||
global.sinon = require('sinon');
|
||||
require('../lib/observe-shim.js');
|
||||
require('./Object.observe');
|
||||
require('./bugs');
|
34
bower_components/peerjs/.bower.json
vendored
Normal file
34
bower_components/peerjs/.bower.json
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "peerjs",
|
||||
"version": "0.3.14",
|
||||
"homepage": "http://peerjs.com",
|
||||
"authors": [
|
||||
"Michelle Bu <michelle@michellebu.com>"
|
||||
],
|
||||
"description": "Simple peer-to-peer data and media using WebRTC.",
|
||||
"main": "peer.js",
|
||||
"keywords": [
|
||||
"WebRTC",
|
||||
"peer",
|
||||
"peerjs",
|
||||
"p2p"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"bower_components",
|
||||
"test",
|
||||
"tests"
|
||||
],
|
||||
"_release": "0.3.14",
|
||||
"_resolution": {
|
||||
"type": "version",
|
||||
"tag": "0.3.14",
|
||||
"commit": "708cb482682a3c7599dd177090e789722e2b8346"
|
||||
},
|
||||
"_source": "git://github.com/peers/bower-peerjs.git",
|
||||
"_target": "~0.3.14",
|
||||
"_originalSource": "peerjs",
|
||||
"_direct": true
|
||||
}
|
39
bower_components/peerjs/README.md
vendored
Normal file
39
bower_components/peerjs/README.md
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
# bower-peerjs
|
||||
|
||||
Install with `bower`:
|
||||
|
||||
```shell
|
||||
bower install peerjs
|
||||
```
|
||||
|
||||
```html
|
||||
<script src="/bower_components/peerjs/peer.js"></script>
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
Documentation is available [here](http://peerjs.com/docs).
|
||||
|
||||
## License
|
||||
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2010-2013 Michelle Bu and Eric Zhang. http://peerjs.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
24
bower_components/peerjs/bower.json
vendored
Normal file
24
bower_components/peerjs/bower.json
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "peerjs",
|
||||
"version": "0.3.14",
|
||||
"homepage": "http://peerjs.com",
|
||||
"authors": [
|
||||
"Michelle Bu <michelle@michellebu.com>"
|
||||
],
|
||||
"description": "Simple peer-to-peer data and media using WebRTC.",
|
||||
"main": "peer.js",
|
||||
"keywords": [
|
||||
"WebRTC",
|
||||
"peer",
|
||||
"peerjs",
|
||||
"p2p"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"bower_components",
|
||||
"test",
|
||||
"tests"
|
||||
]
|
||||
}
|
2939
bower_components/peerjs/peer.js
vendored
Normal file
2939
bower_components/peerjs/peer.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2
bower_components/peerjs/peer.min.js
vendored
Normal file
2
bower_components/peerjs/peer.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -55,8 +55,9 @@ gulp.task 'browser', ->
|
||||
.pipe gulp.dest './build/browser'
|
||||
.pipe uglify()
|
||||
.pipe rename
|
||||
extname: ".min.js"
|
||||
.pipe gulp.dest 'build/browser'
|
||||
extname: ".js"
|
||||
basename: "index"
|
||||
.pipe gulp.dest './'
|
||||
.pipe gulpif '!**/', git.add({args : "-A"})
|
||||
|
||||
gulp.src (files.test.concat files.browser_test), {read: false}
|
||||
|
@ -2,7 +2,7 @@
|
||||
"name": "yatta",
|
||||
"version": "0.1.0",
|
||||
"description": "A Framework that enables Real-Time Collaboration on arbitrary data structures.",
|
||||
"main": "./build/node/index",
|
||||
"main": "./build/node/",
|
||||
"directories": {
|
||||
"lib": "./build/node/"
|
||||
},
|
||||
@ -58,6 +58,7 @@
|
||||
"mocha": "^1.21.4",
|
||||
"sinon": "^1.10.2",
|
||||
"sinon-chai": "^2.5.0",
|
||||
"coffee-errors": "~0.8.6"
|
||||
"coffee-errors": "~0.8.6",
|
||||
"gulp-copy": "0.0.2"
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user