Skip to content

Commit

Permalink
2.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattchewone committed Apr 26, 2019
1 parent bfd91d9 commit b715b2a
Show file tree
Hide file tree
Showing 14 changed files with 6,603 additions and 0 deletions.
60 changes: 60 additions & 0 deletions dist/amd/array/array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*can-observe@2.2.0#array/array*/
define([
'require',
'exports',
'module',
'can-symbol',
'../src/-make-array',
'../src/-make-observe',
'can-event-queue/map',
'can-event-queue/type',
'../src/-helpers',
'../src/-observable-store',
'../src/-computed-helpers',
'../src/-type-helpers'
], function (require, exports, module) {
'use strict';
var canSymbol = require('can-symbol');
var makeArray = require('../src/-make-array');
var makeObserve = require('../src/-make-observe');
var eventMixin = require('can-event-queue/map');
var typeEventMixin = require('can-event-queue/type');
var helpers = require('../src/-helpers');
var observableStore = require('../src/-observable-store');
var computedHelpers = require('../src/-computed-helpers');
var typeHelpers = require('../src/-type-helpers');
var definitionsSymbol = canSymbol.for('can.typeDefinitions');
var proxyKeys = helpers.assignEverything({}, makeArray.proxyKeys());
var ObserveArray;
if (false) {
} else {
var ObserveArray = function (items) {
var prototype = Object.getPrototypeOf(this);
computedHelpers.ensureDefinition(prototype);
typeHelpers.ensureDefinition(prototype);
var instance = this;
var definitions = prototype[definitionsSymbol] || {};
for (var key in definitions) {
Object.defineProperty(instance, key, definitions[key]);
}
this.push.apply(this, items || []);
var localProxyKeys = Object.create(proxyKeys);
localProxyKeys.constructor = this.constructor;
var observable = makeArray.observable(instance, {
observe: makeObserve.observe,
proxyKeys: localProxyKeys,
shouldRecordObservation: typeHelpers.shouldRecordObservationOnAllKeysExceptFunctionsOnProto
});
observableStore.proxiedObjects.set(instance, observable);
observableStore.proxies.add(observable);
return observable;
};
ObserveArray.prototype = Object.create(Array.prototype);
}
eventMixin(ObserveArray.prototype);
typeEventMixin(ObserveArray);
computedHelpers.addMethodsAndSymbols(ObserveArray);
typeHelpers.addMethodsAndSymbols(ObserveArray);
ObserveArray.extend = helpers.makeSimpleExtender(ObserveArray);
module.exports = ObserveArray;
});
42 changes: 42 additions & 0 deletions dist/amd/can-observe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*can-observe@2.2.0#can-observe*/
define([
'require',
'exports',
'module',
'./src/-make-object',
'./src/-make-array',
'./src/-make-function',
'./src/-make-observe',
'./object/object',
'./array/array',
'./src/-computed-helpers',
'./decorators/decorators'
], function (require, exports, module) {
'use strict';
var makeObject = require('./src/-make-object');
var makeArray = require('./src/-make-array');
var makeFunction = require('./src/-make-function');
var makeObserve = require('./src/-make-observe');
var ObserveObject = require('./object/object');
var ObserveArray = require('./array/array');
var computedHelpers = require('./src/-computed-helpers');
var decorators = require('./decorators/decorators');
makeObserve.object = function (object) {
return makeObject.observable(object, makeObserve);
};
makeObserve.array = function (array) {
return makeArray.observable(array, makeObserve);
};
makeObserve.function = function (array) {
return makeFunction.observable(array, makeObserve);
};
makeObserve.observe.Object = ObserveObject;
makeObserve.observe.Array = ObserveArray;
module.exports = makeObserve.observe;
module.exports.defineProperty = function (prototype, prop, makeObservable) {
computedHelpers.ensureDefinition(prototype)[prop] = makeObservable;
};
for (var key in decorators) {
module.exports[key] = decorators[key];
}
});
70 changes: 70 additions & 0 deletions dist/amd/decorators/decorators.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*can-observe@2.2.0#decorators/decorators*/
define([
'require',
'exports',
'module',
'can-reflect',
'can-simple-observable/async',
'can-simple-observable/resolver',
'../src/-computed-helpers'
], function (require, exports, module) {
'use strict';
var canReflect = require('can-reflect');
var AsyncObservable = require('can-simple-observable/async');
var ResolverObservable = require('can-simple-observable/resolver');
var computedHelpers = require('../src/-computed-helpers');
function defineProperty(prototype, prop, makeObservable) {
computedHelpers.ensureDefinition(prototype)[prop] = makeObservable;
}
function asyncBase(config) {
return function (target, key, descriptor) {
if (descriptor.get !== undefined) {
var getter = descriptor.get;
return defineProperty(target, key, function (instance, property) {
function fn(lastSet, resolve) {
if (!resolve) {
return config.default;
}
var promise = getter.call(this, true);
if (canReflect.isPromise(promise)) {
promise.then(resolve);
return config.default;
}
}
return new AsyncObservable(fn, instance, config.default);
});
}
if (descriptor.value !== undefined) {
var method = descriptor.value;
return defineProperty(target, key, function (instance, property) {
return new AsyncObservable(function (lastSet, resolve) {
return method.call(this, resolve);
}, instance, config.default);
});
}
};
}
function resolverBase(config) {
return function (target, key, descriptor) {
if (descriptor.value !== undefined) {
var method = descriptor.value;
return defineProperty(target, key, function (instance, property) {
return new ResolverObservable(method, instance);
});
}
};
}
function optionalConfig(decorator) {
function wrapper(config) {
if (arguments.length === 3) {
return decorator({}).apply(null, arguments);
}
return decorator(config);
}
return wrapper;
}
module.exports = {
async: optionalConfig(asyncBase),
resolver: optionalConfig(resolverBase)
};
});
60 changes: 60 additions & 0 deletions dist/amd/object/object.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*can-observe@2.2.0#object/object*/
define([
'require',
'exports',
'module',
'can-reflect',
'can-symbol',
'../src/-make-observe',
'can-event-queue/map',
'can-event-queue/type',
'../src/-helpers',
'../src/-make-object',
'../src/-observable-store',
'../src/-computed-helpers',
'../src/-type-helpers'
], function (require, exports, module) {
'use strict';
var canReflect = require('can-reflect');
var canSymbol = require('can-symbol');
var makeObserve = require('../src/-make-observe');
var eventMixin = require('can-event-queue/map');
var typeEventMixin = require('can-event-queue/type');
var helpers = require('../src/-helpers');
var makeObject = require('../src/-make-object');
var observableStore = require('../src/-observable-store');
var definitionsSymbol = canSymbol.for('can.typeDefinitions');
var computedHelpers = require('../src/-computed-helpers');
var typeHelpers = require('../src/-type-helpers');
var proxyKeys = helpers.assignEverything({}, makeObject.proxyKeys());
computedHelpers.addKeyDependencies(proxyKeys);
var ObserveObject = function (props) {
var prototype = Object.getPrototypeOf(this);
computedHelpers.ensureDefinition(prototype);
typeHelpers.ensureDefinition(prototype);
var sourceInstance = this;
var definitions = prototype[definitionsSymbol] || {};
for (var key in definitions) {
Object.defineProperty(sourceInstance, key, definitions[key]);
}
if (props !== undefined) {
canReflect.assign(sourceInstance, props);
}
var localProxyKeys = Object.create(proxyKeys);
localProxyKeys.constructor = this.constructor;
var observable = makeObject.observable(sourceInstance, {
observe: makeObserve.observe,
proxyKeys: localProxyKeys,
shouldRecordObservation: typeHelpers.shouldRecordObservationOnAllKeysExceptFunctionsOnProto
});
observableStore.proxiedObjects.set(sourceInstance, observable);
observableStore.proxies.add(observable);
return observable;
};
eventMixin(ObserveObject.prototype);
typeEventMixin(ObserveObject);
computedHelpers.addMethodsAndSymbols(ObserveObject);
typeHelpers.addMethodsAndSymbols(ObserveObject);
ObserveObject.extend = helpers.makeSimpleExtender(ObserveObject);
module.exports = ObserveObject;
});
151 changes: 151 additions & 0 deletions dist/amd/src/-computed-helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*can-observe@2.2.0#src/-computed-helpers*/
define([
'require',
'exports',
'module',
'can-observation',
'can-observation-recorder',
'can-event-queue/map',
'can-reflect',
'can-symbol'
], function (require, exports, module) {
'use strict';
var Observation = require('can-observation');
var ObservationRecorder = require('can-observation-recorder');
var mapBindings = require('can-event-queue/map');
var canReflect = require('can-reflect');
var canSymbol = require('can-symbol');
var canMeta = canSymbol.for('can.meta');
var computedPropertyDefinitionSymbol = canSymbol.for('can.computedPropertyDefinitions');
var onKeyValueSymbol = canSymbol.for('can.onKeyValue');
var offKeyValueSymbol = canSymbol.for('can.offKeyValue');
function ComputedObjectObservationData(instance, prop, observation) {
this.instance = instance;
this.prop = prop;
this.observation = observation;
this.forward = this.forward.bind(this);
}
ComputedObjectObservationData.prototype.bind = function () {
this.bindingCount++;
if (this.bindingCount === 1) {
this.observation.on(this.forward, 'notify');
}
};
ComputedObjectObservationData.prototype.unbind = function () {
this.bindingCount--;
if (this.bindingCount === 0) {
this.observation.off(this.forward, 'notify');
}
};
ComputedObjectObservationData.prototype.forward = function (newValue, oldValue) {
mapBindings.dispatch.call(this.instance, {
type: this.prop,
target: this.instance
}, [
newValue,
oldValue
]);
};
ComputedObjectObservationData.prototype.bindingCount = 0;
function findComputed(instance, key) {
var meta = instance[canMeta];
var target = meta.target;
var computedPropertyDefinitions = target[computedPropertyDefinitionSymbol];
if (computedPropertyDefinitions === undefined) {
return;
}
var computedPropertyDefinition = computedPropertyDefinitions[key];
if (computedPropertyDefinition === undefined) {
return;
}
if (meta.computedKeys[key] === undefined) {
meta.computedKeys[key] = new ComputedObjectObservationData(instance, key, computedPropertyDefinition(instance, key));
}
return meta.computedKeys[key];
}
var computedHelpers = module.exports = {
get: function (instance, key) {
var computedObj = findComputed(instance, key);
if (computedObj === undefined) {
return;
}
ObservationRecorder.add(instance, key.toString());
if (computedObj.bindingCount === 0 && ObservationRecorder.isRecording()) {
Observation.temporarilyBind(computedObj.observation);
}
return { value: canReflect.getValue(computedObj.observation) };
},
set: function (instance, key, value) {
var computedObj = findComputed(instance, key);
if (computedObj === undefined) {
return false;
}
canReflect.setValue(computedObj.observation, value);
return true;
},
bind: function (instance, key) {
var computedObj = findComputed(instance, key);
if (computedObj === undefined) {
return;
}
computedObj.bind();
},
unbind: function (instance, key) {
var computedObj = findComputed(instance, key);
if (computedObj === undefined) {
return;
}
computedObj.unbind();
},
addKeyDependencies: function (proxyKeys) {
var onKeyValue = proxyKeys[onKeyValueSymbol];
var offKeyValue = proxyKeys[offKeyValueSymbol];
canReflect.assignSymbols(proxyKeys, {
'can.onKeyValue': function (key, handler, queue) {
computedHelpers.bind(this, key);
return onKeyValue.apply(this, arguments);
},
'can.offKeyValue': function (key, handler, queue) {
computedHelpers.unbind(this, key);
return offKeyValue.apply(this, arguments);
},
'can.getKeyDependencies': function (key) {
var computedObj = findComputed(this, key);
if (computedObj === undefined) {
return;
}
return { valueDependencies: new Set([computedObj.observation]) };
}
});
},
addMethodsAndSymbols: function (Type) {
Type.prototype.addEventListener = function (key, handler, queue) {
computedHelpers.bind(this, key);
return mapBindings.addEventListener.call(this, key, handler, queue);
};
Type.prototype.removeEventListener = function (key, handler, queue) {
computedHelpers.unbind(this, key);
return mapBindings.removeEventListener.call(this, key, handler, queue);
};
},
ensureDefinition: function (prototype) {
if (!prototype.hasOwnProperty(computedPropertyDefinitionSymbol)) {
var parent = prototype[computedPropertyDefinitionSymbol];
var definitions = prototype[computedPropertyDefinitionSymbol] = Object.create(parent || null);
Object.getOwnPropertyNames(prototype).forEach(function (prop) {
if (prop === 'constructor') {
return;
}
var descriptor = Object.getOwnPropertyDescriptor(prototype, prop);
if (descriptor.get !== undefined) {
var getter = descriptor.get;
definitions[prop] = function (instance, property) {
return new Observation(getter, instance);
};
}
});
}
return prototype[computedPropertyDefinitionSymbol];
}
};
});
Loading

0 comments on commit b715b2a

Please sign in to comment.