Skip to content

Commit

Permalink
Merge pull request CesiumGS#1499 from AnalyticalGraphicsInc/refactorK…
Browse files Browse the repository at this point in the history
…nockoutES5

Remove the need for the WeakMap shim in knockout-es5.
  • Loading branch information
mramato committed Feb 22, 2014
2 parents 67be26b + 44cf6d6 commit 79dad70
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 356 deletions.
12 changes: 0 additions & 12 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,6 @@ https://github.com/SteveSanderson/knockout-es5
>
> 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.
### knockout-es5 WeakMap shim

https://github.com/SteveSanderson/knockout-es5

> Copyright (c) 2012 Brandon Benvie <http://bbenvie.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 with 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.
### topojson

https://github.com/mbostock/topojson
Expand Down
70 changes: 12 additions & 58 deletions Source/ThirdParty/knockout-es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
* MIT license
*/

define(['./weakmap', 'exports'], function(weakmap, exports) {

(function(global, undefined) {
define(function() {
'use strict';

// Model tracking
Expand Down Expand Up @@ -77,21 +75,15 @@ define(['./weakmap', 'exports'], function(weakmap, exports) {
return obj;
}

// Lazily created by `getAllObservablesForObject` below. Has to be created lazily because the
// WeakMap factory isn't available until the module has finished loading (may be async).
var objectToObservableMap;

// Gets or creates the hidden internal key-value collection of observables corresponding to
// properties on the model object.
function getAllObservablesForObject(obj, createIfNotDefined) {
if (!objectToObservableMap) {
objectToObservableMap = weakMapFactory();
}

var result = objectToObservableMap.get(obj);
var result = obj.__knockoutObservables;
if (!result && createIfNotDefined) {
result = {};
objectToObservableMap.set(obj, result);
Object.defineProperty(obj, '__knockoutObservables', {
value : result
});
}
return result;
}
Expand Down Expand Up @@ -181,20 +173,14 @@ define(['./weakmap', 'exports'], function(weakmap, exports) {
return subscribable.subscribe(observable);
}

// Lazily created by `getSubscribableForArray` below. Has to be created lazily because the
// WeakMap factory isn't available until the module has finished loading (may be async).
var arraySubscribablesMap;

// Gets or creates a subscribable that fires after each array mutation
function getSubscribableForArray(ko, arrayInstance) {
if (!arraySubscribablesMap) {
arraySubscribablesMap = weakMapFactory();
}

var subscribable = arraySubscribablesMap.get(arrayInstance);
var subscribable = arrayInstance.__knockoutSubscribable;
if (!subscribable) {
subscribable = new ko.subscribable();
arraySubscribablesMap.set(arrayInstance, subscribable);
Object.defineProperty(arrayInstance, '__knockoutSubscribable', {
value : subscribable
});

var notificationPauseSignal = {};
wrapStandardArrayMutators(arrayInstance, subscribable, notificationPauseSignal);
Expand Down Expand Up @@ -279,18 +265,6 @@ define(['./weakmap', 'exports'], function(weakmap, exports) {
}
}

// Module initialisation
// ---------------------
//
// When this script is first evaluated, it works out what kind of module loading scenario
// it is in (Node.js or a browser `<script>` tag), stashes a reference to its dependencies
// (currently that's just the WeakMap shim), and then finally attaches itself to whichever
// instance of Knockout.js it can find.

// A function that returns a new ES6-compatible WeakMap instance (using ES5 shim if needed).
// Instantiated by prepareExports, accounting for which module loader is being used.
var weakMapFactory;

// Extends a Knockout instance with Knockout-ES5 functionality
function attachToKo(ko) {
ko.track = track;
Expand All @@ -299,27 +273,7 @@ define(['./weakmap', 'exports'], function(weakmap, exports) {
ko.defineProperty = defineComputedProperty;
}

// Determines which module loading scenario we're in, grabs dependencies, and attaches to KO
function prepareExports() {
if (typeof module !== 'undefined') {
// Node.js case - load KO and WeakMap modules synchronously
var ko = require('knockout'),
WM = require('weakmap');
attachToKo(ko);
weakMapFactory = function() { return new WM(); };
module.exports = ko;
} else if ('ko' in global) {
// Non-module case - attach to the global instance, and assume a global WeakMap constructor
attachToKo(global.ko);
weakMapFactory = function() { return new global.WeakMap(); };
} else if (typeof weakmap !== 'undefined') {
weakMapFactory = function() { return new weakmap.WeakMap(); };
exports.attachToKo = attachToKo;
}
}

prepareExports();

})(this);

return {
attachToKo : attachToKo
};
});
Loading

0 comments on commit 79dad70

Please sign in to comment.