From 7a926e6973d95db27ff297b4270411e4ee36c25c Mon Sep 17 00:00:00 2001 From: Kevin Phillips Date: Mon, 29 Jan 2018 12:37:25 -0600 Subject: [PATCH] 2.0.0 --- dist/amd/array/array.js | 56 + dist/amd/can-observe.js | 31 + dist/amd/object/object.js | 55 + dist/amd/src/-add-get-key-dependencies.js | 24 + dist/amd/src/-getter-helpers.js | 110 + dist/amd/src/-helpers.js | 79 + dist/amd/src/-make-array.js | 201 + dist/amd/src/-make-function.js | 95 + dist/amd/src/-make-object.js | 192 + dist/amd/src/-make-observe.js | 44 + dist/amd/src/-memoize-getter.js | 65 + dist/amd/src/-observable-store.js | 7 + dist/amd/src/-symbols.js | 14 + dist/global/can-observe.js | 4543 +++++++++++++++++++++ 14 files changed, 5516 insertions(+) create mode 100644 dist/amd/array/array.js create mode 100644 dist/amd/can-observe.js create mode 100644 dist/amd/object/object.js create mode 100644 dist/amd/src/-add-get-key-dependencies.js create mode 100644 dist/amd/src/-getter-helpers.js create mode 100644 dist/amd/src/-helpers.js create mode 100644 dist/amd/src/-make-array.js create mode 100644 dist/amd/src/-make-function.js create mode 100644 dist/amd/src/-make-object.js create mode 100644 dist/amd/src/-make-observe.js create mode 100644 dist/amd/src/-memoize-getter.js create mode 100644 dist/amd/src/-observable-store.js create mode 100644 dist/amd/src/-symbols.js create mode 100644 dist/global/can-observe.js diff --git a/dist/amd/array/array.js b/dist/amd/array/array.js new file mode 100644 index 0000000..18cf511 --- /dev/null +++ b/dist/amd/array/array.js @@ -0,0 +1,56 @@ +/*can-observe@2.0.0-pre.22#array/array*/ +define([ + 'require', + 'exports', + 'module', + 'can-symbol', + '../src/-make-array', + '../src/-make-observe', + 'can-event-queue/map', + '../src/-helpers', + '../src/-observable-store', + '../src/-getter-helpers' +], function (require, exports, module) { + 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 helpers = require('../src/-helpers'); + var observableStore = require('../src/-observable-store'); + var getterHelpers = require('../src/-getter-helpers'); + var definitionsSymbol = canSymbol.for('can.typeDefinitions'); + var computedDefinitionsSymbol = canSymbol.for('can.computedDefinitions'); + var proxyKeys = helpers.assignEverything({}, makeArray.proxyKeys()); + getterHelpers.addMemoizedGetterBindings(proxyKeys); + var ObserveArray; + if (false) { + } else { + var ObserveArray = function (items) { + var prototype = Object.getPrototypeOf(this); + if (prototype[computedDefinitionsSymbol] === undefined) { + prototype[computedDefinitionsSymbol] = getterHelpers.setupComputedProperties(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: getterHelpers.shouldRecordObservationOnAllKeysExceptFunctionsOnProto + }); + observableStore.proxiedObjects.set(instance, observable); + observableStore.proxies.add(observable); + return observable; + }; + ObserveArray.prototype = Object.create(Array.prototype); + } + eventMixin(ObserveArray.prototype); + getterHelpers.addMethodsAndSymbols(ObserveArray); + ObserveArray.extend = helpers.makeSimpleExtender(ObserveArray); + module.exports = ObserveArray; +}); \ No newline at end of file diff --git a/dist/amd/can-observe.js b/dist/amd/can-observe.js new file mode 100644 index 0000000..72b0ccb --- /dev/null +++ b/dist/amd/can-observe.js @@ -0,0 +1,31 @@ +/*can-observe@2.0.0-pre.22#can-observe*/ +define([ + 'require', + 'exports', + 'module', + './src/-make-object', + './src/-make-array', + './src/-make-function', + './src/-make-observe', + './object/object', + './array/array' +], function (require, exports, module) { + 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'); + 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; +}); \ No newline at end of file diff --git a/dist/amd/object/object.js b/dist/amd/object/object.js new file mode 100644 index 0000000..1011dc6 --- /dev/null +++ b/dist/amd/object/object.js @@ -0,0 +1,55 @@ +/*can-observe@2.0.0-pre.22#object/object*/ +define([ + 'require', + 'exports', + 'module', + 'can-reflect', + 'can-symbol', + '../src/-make-observe', + 'can-event-queue/map', + '../src/-helpers', + '../src/-make-object', + '../src/-observable-store', + '../src/-getter-helpers' +], function (require, exports, module) { + var canReflect = require('can-reflect'); + var canSymbol = require('can-symbol'); + var makeObserve = require('../src/-make-observe'); + var eventMixin = require('can-event-queue/map'); + var helpers = require('../src/-helpers'); + var makeObject = require('../src/-make-object'); + var observableStore = require('../src/-observable-store'); + var definitionsSymbol = canSymbol.for('can.typeDefinitions'); + var getterHelpers = require('../src/-getter-helpers'); + var computedDefinitionsSymbol = canSymbol.for('can.computedDefinitions'); + var proxyKeys = helpers.assignEverything({}, makeObject.proxyKeys()); + getterHelpers.addMemoizedGetterBindings(proxyKeys); + var ObserveObject = function (props) { + var prototype = Object.getPrototypeOf(this); + if (prototype[computedDefinitionsSymbol] === undefined) { + prototype[computedDefinitionsSymbol] = getterHelpers.setupComputedProperties(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: getterHelpers.shouldRecordObservationOnAllKeysExceptFunctionsOnProto + }); + observableStore.proxiedObjects.set(sourceInstance, observable); + observableStore.proxies.add(observable); + return observable; + }; + eventMixin(ObserveObject.prototype); + getterHelpers.addMethodsAndSymbols(ObserveObject); + ObserveObject.extend = helpers.makeSimpleExtender(ObserveObject); + module.exports = ObserveObject; +}); \ No newline at end of file diff --git a/dist/amd/src/-add-get-key-dependencies.js b/dist/amd/src/-add-get-key-dependencies.js new file mode 100644 index 0000000..9d178cd --- /dev/null +++ b/dist/amd/src/-add-get-key-dependencies.js @@ -0,0 +1,24 @@ +/*can-observe@2.0.0-pre.22#src/-add-get-key-dependencies*/ +define([ + 'require', + 'exports', + 'module', + 'can-symbol' +], function (require, exports, module) { + var canSymbol = require('can-symbol'); + var getKeyDependenciesSymbol = canSymbol.for('can.getKeyDependencies'); + var computedDefinitionsSymbol = canSymbol.for('can.computedDefinitions'); + module.exports = function addGetterKeyDependencies(obj) { + obj[getKeyDependenciesSymbol] = function getKeyDependencies(key) { + var computed = this[computedDefinitionsSymbol]; + if (computed) { + var getObservation = computed[key]; + var observationData = getObservation && getObservation(this); + if (observationData != null) { + return { valueDependencies: new Set([observationData.observation]) }; + } + } + }; + return obj; + }; +}); \ No newline at end of file diff --git a/dist/amd/src/-getter-helpers.js b/dist/amd/src/-getter-helpers.js new file mode 100644 index 0000000..375f8b0 --- /dev/null +++ b/dist/amd/src/-getter-helpers.js @@ -0,0 +1,110 @@ +/*can-observe@2.0.0-pre.22#src/-getter-helpers*/ +define([ + 'require', + 'exports', + 'module', + 'can-symbol', + 'can-event-queue/type', + 'can-reflect', + './-memoize-getter', + 'can-queues', + 'can-event-queue/map' +], function (require, exports, module) { + var canSymbol = require('can-symbol'); + var definitionsSymbol = canSymbol.for('can.typeDefinitions'); + var typeEventMixin = require('can-event-queue/type'); + var canReflect = require('can-reflect'); + var memoizeGetter = require('./-memoize-getter'); + var queues = require('can-queues'); + var eventMixin = require('can-event-queue/map'); + var computedDefinitionsSymbol = canSymbol.for('can.computedDefinitions'); + var metaSymbol = canSymbol.for('can.meta'); + var getterHelpers = { + ensureTypeDefinition: function (obj) { + var typeDefs = obj.prototype[definitionsSymbol]; + if (!typeDefs) { + typeDefs = obj.prototype[definitionsSymbol] = Object.create(null); + } + return typeDefs; + }, + shouldRecordObservationOnAllKeysExceptFunctionsOnProto: function (keyInfo, meta) { + return meta.preventSideEffects === 0 && !keyInfo.isAccessor && (keyInfo.targetHasOwnKey || !keyInfo.protoHasKey && !Object.isSealed(meta.target) || keyInfo.protoHasKey && typeof targetValue !== 'function'); + }, + addMethodsAndSymbols: function (Type) { + typeEventMixin(Type); + canReflect.assignSymbols(Type, { + 'can.defineInstanceKey': function (prop, value) { + getterHelpers.ensureTypeDefinition(this)[prop] = value; + }, + 'can.dispatchInstanceBoundChange': function (obj, isBound) { + var meta = this[metaSymbol]; + if (meta) { + var lifecycleHandlers = meta.lifecycleHandlers; + if (lifecycleHandlers) { + queues.enqueueByQueue(lifecycleHandlers.getNode([]), this, [ + obj, + isBound + ]); + } + } + } + }); + Type.prototype.addEventListener = function (key, handler, queue) { + var getObservation = this[computedDefinitionsSymbol][key]; + if (getObservation !== undefined) { + getObservation(this).bind(); + } + return eventMixin.addEventListener.call(this, key, handler, queue); + }; + Type.prototype.removeEventListener = function (key, handler, queue) { + var getObservation = this[computedDefinitionsSymbol][key]; + if (getObservation !== undefined) { + getObservation(this).unbind(); + } + return eventMixin.removeEventListener.call(this, key, handler, queue); + }; + }, + setupComputedProperties: function (prototype) { + var computed = {}; + Object.getOwnPropertyNames(prototype).forEach(function (prop) { + var descriptor = Object.getOwnPropertyDescriptor(prototype, prop); + if (descriptor.get !== undefined) { + var getObservationData = memoizeGetter(prototype, prop, descriptor); + computed[prop] = getObservationData; + } + }); + return computed; + }, + addMemoizedGetterBindings: function (proxyKeys) { + return canReflect.assignSymbols(proxyKeys, { + 'can.onKeyValue': function (key, handler, queue) { + var getObservation = this[computedDefinitionsSymbol][key]; + if (getObservation !== undefined) { + getObservation(this).bind(); + } + var handlers = this[metaSymbol].handlers; + handlers.add([ + key, + 'onKeyValue', + queue || 'notify', + handler + ]); + }, + 'can.offKeyValue': function (key, handler, queue) { + var getObservation = this[computedDefinitionsSymbol][key]; + if (getObservation !== undefined) { + getObservation(this).unbind(); + } + var handlers = this[metaSymbol].handlers; + handlers.delete([ + key, + 'onKeyValue', + queue || 'notify', + handler + ]); + } + }); + } + }; + module.exports = getterHelpers; +}); \ No newline at end of file diff --git a/dist/amd/src/-helpers.js b/dist/amd/src/-helpers.js new file mode 100644 index 0000000..2bca25c --- /dev/null +++ b/dist/amd/src/-helpers.js @@ -0,0 +1,79 @@ +/*can-observe@2.0.0-pre.22#src/-helpers*/ +define([ + 'require', + 'exports', + 'module', + 'can-symbol' +], function (require, exports, module) { + var canSymbol = require('can-symbol'); + var metaSymbol = canSymbol.for('can.meta'); + var definitionsSymbol = canSymbol.for('can.typeDefinitions'); + var classTest = /^\s*class\s+/; + var helpers = { + assignEverything: function (d, s) { + Object.getOwnPropertyNames(s).concat(Object.getOwnPropertySymbols(s)).forEach(function (key) { + Object.defineProperty(d, key, Object.getOwnPropertyDescriptor(s, key)); + }); + return d; + }, + isBuiltInButNotArrayOrPlainObject: function (obj) { + if (Array.isArray(obj)) { + return false; + } + if (typeof obj === 'function') { + var fnCode = obj.toString(); + if (fnCode.indexOf('[native code]') > 0) { + return true; + } else { + return false; + } + } else { + var toString = Object.prototype.toString.call(obj); + return toString !== '[object Object]' && toString.indexOf('[object ') !== -1; + } + }, + inheritsFromArray: function (obj) { + var cur = obj; + do { + if (Array.isArray(cur)) { + return true; + } + cur = Object.getPrototypeOf(cur); + } while (cur); + return false; + }, + isClass: function (obj) { + return typeof obj === 'function' && classTest.test(obj.toString()); + }, + supportsClass: function () { + try { + eval('"use strict"; class A{};'); + return true; + } catch (e) { + return false; + } + }(), + makeSimpleExtender: function (BaseType) { + return function etend(name, staticProps, prototypeProps) { + var Type = function () { + var source = this; + var instance = BaseType.apply(this, arguments); + if (source.init) { + instance[metaSymbol].preventSideEffects++; + source.init.apply(instance, arguments); + instance[metaSymbol].preventSideEffects--; + } + return instance; + }; + helpers.assignEverything(Type, BaseType); + helpers.assignEverything(Type, staticProps || {}); + Type.prototype = Object.create(BaseType.prototype); + helpers.assignEverything(Type.prototype, prototypeProps || {}); + Type.prototype.constructor = Type; + Type.prototype[definitionsSymbol] = Object.create(BaseType.prototype[definitionsSymbol] || null); + return Type; + }; + } + }; + module.exports = helpers; +}); \ No newline at end of file diff --git a/dist/amd/src/-make-array.js b/dist/amd/src/-make-array.js new file mode 100644 index 0000000..6500f4b --- /dev/null +++ b/dist/amd/src/-make-array.js @@ -0,0 +1,201 @@ +/*can-observe@2.0.0-pre.22#src/-make-array*/ +define([ + 'require', + 'exports', + 'module', + 'can-observation-recorder', + 'can-event-queue/map', + 'can-reflect', + './-make-object', + './-symbols', + './-observable-store', + './-helpers' +], function (require, exports, module) { + var ObservationRecorder = require('can-observation-recorder'); + var mapBindings = require('can-event-queue/map'); + var canReflect = require('can-reflect'); + var makeObject = require('./-make-object'); + var symbols = require('./-symbols'); + var observableStore = require('./-observable-store'); + var helpers = require('./-helpers'); + var isInteger = Number.isInteger || function (value) { + return typeof value === 'number' && isFinite(value) && Math.floor(value) === value; + }; + function didLengthChangeCauseDeletions(key, value, old) { + return key === 'length' && value < old; + } + var mutateMethods = { + 'push': function (arr, args) { + return [{ + index: arr.length - args.length, + deleteCount: 0, + insert: args, + type: 'splice' + }]; + }, + 'pop': function (arr) { + return [{ + index: arr.length, + deleteCount: 1, + insert: [], + type: 'splice' + }]; + }, + 'shift': function () { + return [{ + index: 0, + deleteCount: 1, + insert: [], + type: 'splice' + }]; + }, + 'unshift': function (arr, args) { + return [{ + index: 0, + deleteCount: 0, + insert: args, + type: 'splice' + }]; + }, + 'splice': function (arr, args) { + return [{ + index: args[0], + deleteCount: args[1], + insert: args.slice(2), + type: 'splice' + }]; + }, + 'sort': function (arr) { + return [{ + index: 0, + deleteCount: arr.length, + insert: arr, + type: 'splice' + }]; + }, + 'reverse': function (arr, args, old) { + return [{ + index: 0, + deleteCount: arr.length, + insert: arr, + type: 'splice' + }]; + } + }; + canReflect.eachKey(mutateMethods, function (makePatches, prop) { + var protoFn = Array.prototype[prop]; + var mutateMethod = function () { + var meta = this[symbols.metaSymbol], makeSideEffects = meta.preventSideEffects === 0, oldLength = meta.target.length; + meta.preventSideEffects++; + var ret = protoFn.apply(meta.target, arguments); + var patches = makePatches(meta.target, Array.from(arguments), oldLength); + if (makeSideEffects === true) { + mapBindings.dispatch.call(meta.proxy, { + type: 'length', + patches: patches + }, [ + meta.target.length, + oldLength + ]); + } + meta.preventSideEffects--; + return ret; + }; + observableStore.proxiedObjects.set(protoFn, mutateMethod); + observableStore.proxies.add(mutateMethod); + }); + Object.getOwnPropertyNames(Array.prototype).forEach(function (prop) { + var protoFn = Array.prototype[prop]; + if (observableStore.proxiedObjects.has(protoFn)) { + return; + } + if (prop !== 'constructor' && typeof protoFn === 'function') { + var arrayMethod = function () { + ObservationRecorder.add(this, symbols.patchesSymbol); + var meta = this[symbols.metaSymbol]; + meta.preventSideEffects++; + var ret = protoFn.apply(this, arguments); + meta.preventSideEffects--; + return meta.options.observe(ret); + }; + observableStore.proxiedObjects.set(protoFn, arrayMethod); + observableStore.proxies.add(arrayMethod); + } + }); + var proxyKeys = helpers.assignEverything(Object.create(null), makeObject.proxyKeys()); + var makeArray = { + observable: function (array, options) { + if (options.shouldRecordObservation === undefined) { + options.shouldRecordObservation = makeObject.shouldRecordObservationOnOwnAndMissingKeys; + } + var meta = { + target: array, + proxyKeys: options.proxyKeys !== undefined ? options.proxyKeys : Object.create(makeArray.proxyKeys()), + options: options, + preventSideEffects: 0 + }; + meta.proxyKeys[symbols.metaSymbol] = meta; + meta.proxy = new Proxy(array, { + get: makeObject.get.bind(meta), + set: makeArray.set.bind(meta), + ownKeys: makeObject.ownKeys.bind(meta), + deleteProperty: makeObject.deleteProperty.bind(meta), + meta: meta + }); + mapBindings.addHandlers(meta.proxy, meta); + return meta.proxy; + }, + proxyKeys: function () { + return proxyKeys; + }, + set: function (target, key, value, receiver) { + if (receiver !== this.proxy) { + return makeObject.setKey(receiver, key, value, this); + } + value = makeObject.getValueToSet(key, value, this); + var startingLength = target.length; + makeObject.setValueAndOnChange(key, value, this, function (key, value, meta, hadOwn, old) { + var patches = [{ + key: key, + type: hadOwn ? 'set' : 'add', + value: value + }]; + var numberKey = +key; + if (isInteger(numberKey)) { + if (!hadOwn && numberKey > startingLength) { + patches.push({ + index: startingLength, + deleteCount: 0, + insert: target.slice(startingLength), + type: 'splice' + }); + } else { + patches.push.apply(patches, mutateMethods.splice(target, [ + numberKey, + 1, + value + ])); + } + } + if (didLengthChangeCauseDeletions(key, value, old, meta)) { + patches.push({ + index: value, + deleteCount: old - value, + insert: [], + type: 'splice' + }); + } + mapBindings.dispatch.call(meta.proxy, { + type: key, + patches: patches, + keyChanged: !hadOwn ? key : undefined + }, [ + value, + old + ]); + }); + return true; + } + }; + module.exports = makeArray; +}); \ No newline at end of file diff --git a/dist/amd/src/-make-function.js b/dist/amd/src/-make-function.js new file mode 100644 index 0000000..7c0e7a2 --- /dev/null +++ b/dist/amd/src/-make-function.js @@ -0,0 +1,95 @@ +/*can-observe@2.0.0-pre.22#src/-make-function*/ +define([ + 'require', + 'exports', + 'module', + 'can-reflect', + './-make-object', + './-symbols', + './-observable-store', + 'can-event-queue/map', + 'can-event-queue/type', + './-helpers' +], function (require, exports, module) { + var canReflect = require('can-reflect'); + var makeObject = require('./-make-object'); + var symbols = require('./-symbols'); + var observableStore = require('./-observable-store'); + var mapBindings = require('can-event-queue/map'); + var typeBindings = require('can-event-queue/type'); + var helpers = require('./-helpers'); + var proxyKeys = helpers.assignEverything(Object.create(null), makeObject.proxyKeys()); + typeBindings(proxyKeys); + canReflect.assignSymbols(proxyKeys, { + 'can.defineInstanceKey': function (prop, value) { + this[symbols.metaSymbol].definitions[prop] = value; + } + }); + var makeFunction = { + observable: function (object, options) { + if (options.shouldRecordObservation === undefined) { + options.shouldRecordObservation = makeObject.shouldRecordObservationOnOwnAndMissingKeys; + } + var proxyKeys = Object.create(makeFunction.proxyKeys()); + var meta = { + target: object, + proxyKeys: proxyKeys, + options: options, + definitions: {}, + isClass: helpers.isClass(object), + preventSideEffects: 0 + }; + proxyKeys[symbols.metaSymbol] = meta; + meta.proxy = new Proxy(object, { + get: makeObject.get.bind(meta), + set: makeObject.set.bind(meta), + ownKeys: makeObject.ownKeys.bind(meta), + deleteProperty: makeObject.deleteProperty.bind(meta), + construct: makeFunction.construct.bind(meta), + apply: makeFunction.apply.bind(meta), + meta: meta + }); + mapBindings.addHandlers(meta.proxy, meta); + typeBindings.addHandlers(meta.proxy, meta); + observableStore.proxiedObjects.set(object, meta.proxy); + observableStore.proxies.add(meta.proxy); + if (meta.target.prototype && meta.target.prototype.constructor === meta.target) { + var prototype = meta.proxy.prototype; + prototype.constructor = meta.proxy; + } + return meta.proxy; + }, + construct: function (target, argumentsList, newTarget) { + var instanceTarget, key; + if (this.isClass) { + instanceTarget = Reflect.construct(target, argumentsList, newTarget); + for (key in this.definitions) { + Object.defineProperty(instanceTarget, key, this.definitions[key]); + } + return this.options.observe(instanceTarget); + } else { + instanceTarget = Object.create(this.proxy.prototype); + for (key in this.definitions) { + Object.defineProperty(instanceTarget, key, this.definitions[key]); + } + var instance = this.options.observe(instanceTarget); + instance[symbols.metaSymbol].preventSideEffects++; + var res = target.apply(instance, argumentsList); + instance[symbols.metaSymbol].preventSideEffects--; + if (res) { + return res; + } else { + return instance; + } + } + }, + apply: function (target, thisArg, argumentsList) { + var ret = this.target.apply(thisArg, argumentsList); + return this.options.observe(ret); + }, + proxyKeys: function () { + return proxyKeys; + } + }; + module.exports = makeFunction; +}); \ No newline at end of file diff --git a/dist/amd/src/-make-object.js b/dist/amd/src/-make-object.js new file mode 100644 index 0000000..9a4e091 --- /dev/null +++ b/dist/amd/src/-make-object.js @@ -0,0 +1,192 @@ +/*can-observe@2.0.0-pre.22#src/-make-object*/ +define([ + 'require', + 'exports', + 'module', + 'can-reflect', + 'can-observation-recorder', + 'can-event-queue/map', + './-symbols', + './-observable-store', + './-helpers', + './-add-get-key-dependencies' +], function (require, exports, module) { + var canReflect = require('can-reflect'); + var ObservationRecorder = require('can-observation-recorder'); + var mapBindings = require('can-event-queue/map'); + var symbols = require('./-symbols'); + var observableStore = require('./-observable-store'); + var helpers = require('./-helpers'); + var addGetterKeyDependencies = require('./-add-get-key-dependencies'); + var hasOwn = Object.prototype.hasOwnProperty; + var isSymbolLike = canReflect.isSymbolLike; + var proxyKeys = Object.create(null); + Object.getOwnPropertySymbols(mapBindings).forEach(function (symbol) { + proxyKeys[symbol] = mapBindings[symbol]; + }); + addGetterKeyDependencies(proxyKeys); + var makeObject = { + observable: function (object, options) { + if (options.shouldRecordObservation === undefined) { + options.shouldRecordObservation = makeObject.shouldRecordObservationOnOwnAndMissingKeys; + } + var meta = { + target: object, + proxyKeys: options.proxyKeys !== undefined ? options.proxyKeys : Object.create(makeObject.proxyKeys()), + options: options, + preventSideEffects: 0 + }; + meta.proxyKeys[symbols.metaSymbol] = meta; + meta.proxy = new Proxy(object, { + get: makeObject.get.bind(meta), + set: makeObject.set.bind(meta), + ownKeys: makeObject.ownKeys.bind(meta), + deleteProperty: makeObject.deleteProperty.bind(meta), + meta: meta + }); + mapBindings.addHandlers(meta.proxy, meta); + return meta.proxy; + }, + proxyKeys: function () { + return proxyKeys; + }, + get: function (target, key, receiver) { + var proxyKey = this.proxyKeys[key]; + if (proxyKey !== undefined) { + return proxyKey; + } + if (isSymbolLike(key)) { + return target[key]; + } + var keyInfo = makeObject.getKeyInfo(target, key, receiver, this); + var value = keyInfo.targetValue; + if (!keyInfo.valueIsInvariant) { + value = makeObject.getValueFromStore(key, value, this); + } + if (this.options.shouldRecordObservation(keyInfo, this)) { + ObservationRecorder.add(this.proxy, key.toString()); + } + if (keyInfo.parentObservableGetCalledOn) { + ObservationRecorder.add(keyInfo.parentObservableGetCalledOn, key.toString()); + } + return value; + }, + set: function (target, key, value, receiver) { + if (receiver !== this.proxy) { + return makeObject.setKey(receiver, key, value, this); + } + value = makeObject.getValueToSet(key, value, this); + makeObject.setValueAndOnChange(key, value, this, function (key, value, meta, hadOwn, old) { + mapBindings.dispatch.call(meta.proxy, { + type: key, + patches: [{ + key: key, + type: hadOwn ? 'set' : 'add', + value: value + }], + keyChanged: !hadOwn ? key : undefined + }, [ + value, + old + ]); + }); + return true; + }, + deleteProperty: function (target, key) { + var old = this.target[key], deleteSuccessful = delete this.target[key]; + if (deleteSuccessful && this.preventSideEffects === 0 && old !== undefined) { + mapBindings.dispatch.call(this.proxy, { + type: key, + patches: [{ + key: key, + type: 'delete' + }], + keyChanged: key + }, [ + undefined, + old + ]); + } + return deleteSuccessful; + }, + ownKeys: function (target, key) { + ObservationRecorder.add(this.proxy, symbols.keysSymbol); + return Object.getOwnPropertyNames(this.target).concat(Object.getOwnPropertySymbols(this.target)).concat(Object.getOwnPropertySymbols(this.proxyKeys)); + }, + getKeyInfo: function (target, key, receiver, meta) { + var descriptor = Object.getOwnPropertyDescriptor(target, key); + var propertyInfo = { + key: key, + descriptor: descriptor, + targetHasOwnKey: Boolean(descriptor), + getCalledOnParent: receiver !== meta.proxy, + protoHasKey: false, + valueIsInvariant: false, + targetValue: undefined, + isAccessor: false + }; + if (propertyInfo.getCalledOnParent === true) { + propertyInfo.parentObservableGetCalledOn = observableStore.proxiedObjects.get(receiver); + } + if (descriptor !== undefined) { + propertyInfo.valueIsInvariant = descriptor.writable === false; + if (descriptor.get !== undefined) { + propertyInfo.targetValue = descriptor.get.call(propertyInfo.parentObservableGetCalledOn || receiver); + propertyInfo.isAccessor = true; + } else { + propertyInfo.targetValue = descriptor.value; + } + } else { + propertyInfo.targetValue = meta.target[key]; + propertyInfo.protoHasKey = propertyInfo.targetValue !== undefined ? true : key in target; + } + return propertyInfo; + }, + shouldRecordObservationOnOwnAndMissingKeys: function (keyInfo, meta) { + return meta.preventSideEffects === 0 && !keyInfo.isAccessor && (keyInfo.targetHasOwnKey || !keyInfo.protoHasKey && !Object.isSealed(meta.target)); + }, + setKey: function (receiver, key, value) { + Object.defineProperty(receiver, key, { + value: value, + configurable: true, + enumerable: true, + writable: true + }); + return true; + }, + getValueToSet: function (key, value, meta) { + if (!canReflect.isSymbolLike(key) && meta.handlers.getNode([key])) { + return makeObject.getValueFromStore(key, value, meta); + } + return value; + }, + getValueFromStore: function (key, value, meta) { + if (!canReflect.isPrimitive(value) && !canReflect.isObservableLike(value) && !observableStore.proxies.has(value)) { + if (observableStore.proxiedObjects.has(value)) { + value = observableStore.proxiedObjects.get(value); + } else if (!helpers.isBuiltInButNotArrayOrPlainObject(value)) { + value = meta.options.observe(value); + } + } + return value; + }, + setValueAndOnChange: function (key, value, data, onChange) { + var old, change; + var hadOwn = hasOwn.call(data.target, key); + var descriptor = Object.getOwnPropertyDescriptor(data.target, key); + if (descriptor && descriptor.set) { + descriptor.set.call(data.proxy, value); + } else { + old = data.target[key]; + change = old !== value; + if (change) { + data.target[key] = value; + if (data.preventSideEffects === 0) { + onChange(key, value, data, hadOwn, old); + } + } + } + } + }; + module.exports = makeObject; +}); \ No newline at end of file diff --git a/dist/amd/src/-make-observe.js b/dist/amd/src/-make-observe.js new file mode 100644 index 0000000..0f919c6 --- /dev/null +++ b/dist/amd/src/-make-observe.js @@ -0,0 +1,44 @@ +/*can-observe@2.0.0-pre.22#src/-make-observe*/ +define([ + 'require', + 'exports', + 'module', + 'can-reflect', + './-observable-store', + './-helpers' +], function (require, exports, module) { + var canReflect = require('can-reflect'); + var observables = require('./-observable-store'); + var helpers = require('./-helpers'); + var makeObserve = { + observe: function (value) { + if (canReflect.isPrimitive(value)) { + return value; + } + var observable = observables.proxiedObjects.get(value); + if (observable) { + return observable; + } + if (observables.proxies.has(value)) { + return value; + } + if (helpers.isBuiltInButNotArrayOrPlainObject(value)) { + return value; + } + if (typeof value === 'function') { + observable = makeObserve.function(value); + } else if (helpers.inheritsFromArray(value)) { + observable = makeObserve.array(value); + } else { + observable = makeObserve.object(value); + } + observables.proxiedObjects.set(value, observable); + observables.proxies.add(observable); + return observable; + }, + 'object': null, + 'array': null, + 'function': null + }; + module.exports = makeObserve; +}); \ No newline at end of file diff --git a/dist/amd/src/-memoize-getter.js b/dist/amd/src/-memoize-getter.js new file mode 100644 index 0000000..4fe59da --- /dev/null +++ b/dist/amd/src/-memoize-getter.js @@ -0,0 +1,65 @@ +/*can-observe@2.0.0-pre.22#src/-memoize-getter*/ +define([ + 'require', + 'exports', + 'module', + 'can-observation', + 'can-observation-recorder', + './-observable-store' +], function (require, exports, module) { + var Observation = require('can-observation'); + var ObservationRecorder = require('can-observation-recorder'); + var observableStore = require('./-observable-store'); + function MemoizedGetterObservationData(instance, prop, getter) { + this.prop = prop; + this.instance = instance; + this.forward = this.forward.bind(this); + this.observation = new Observation(getter, instance, { isObservable: false }); + } + MemoizedGetterObservationData.prototype.bind = function (observationData) { + this.bindingCount++; + if (this.bindingCount === 1) { + this.observation.on(this.forward, 'notify'); + } + }; + MemoizedGetterObservationData.prototype.unbind = function (observationData) { + this.bindingCount--; + if (this.bindingCount === 0) { + this.observation.off(this.forward, 'notify'); + } + }; + MemoizedGetterObservationData.prototype.forward = function (newValue, oldValue) { + this.instance.dispatch({ + type: this.prop, + target: this.instance + }, [ + newValue, + oldValue + ]); + }; + MemoizedGetterObservationData.prototype.bindingCount = 0; + module.exports = function memoize(Type, prop, definition) { + var instanceToObservationData = new WeakMap(); + function getObservationDataFor(instance) { + var observationData = instanceToObservationData.get(instance); + if (!observationData) { + observationData = new MemoizedGetterObservationData(instance, prop, definition.get); + instanceToObservationData.set(instance, observationData); + } + return observationData; + } + Object.defineProperty(Type, prop, { + enumerable: definition.enumerable, + get: function memoized() { + var instance = observableStore.proxiedObjects.get(this) || this; + var observationData = getObservationDataFor(instance); + ObservationRecorder.add(instance, prop.toString()); + if (!observationData.observation.bound && ObservationRecorder.isRecording()) { + Observation.temporarilyBind(observationData.observation); + } + return observationData.observation.get(); + } + }); + return getObservationDataFor; + }; +}); \ No newline at end of file diff --git a/dist/amd/src/-observable-store.js b/dist/amd/src/-observable-store.js new file mode 100644 index 0000000..9cbb54a --- /dev/null +++ b/dist/amd/src/-observable-store.js @@ -0,0 +1,7 @@ +/*can-observe@2.0.0-pre.22#src/-observable-store*/ +define(function (require, exports, module) { + module.exports = { + proxiedObjects: new WeakMap(), + proxies: new WeakSet() + }; +}); \ No newline at end of file diff --git a/dist/amd/src/-symbols.js b/dist/amd/src/-symbols.js new file mode 100644 index 0000000..b46f167 --- /dev/null +++ b/dist/amd/src/-symbols.js @@ -0,0 +1,14 @@ +/*can-observe@2.0.0-pre.22#src/-symbols*/ +define([ + 'require', + 'exports', + 'module', + 'can-symbol' +], function (require, exports, module) { + var canSymbol = require('can-symbol'); + module.exports = { + metaSymbol: canSymbol.for('can.meta'), + patchesSymbol: 'can.patches', + keysSymbol: 'can.keys' + }; +}); \ No newline at end of file diff --git a/dist/global/can-observe.js b/dist/global/can-observe.js new file mode 100644 index 0000000..9b13229 --- /dev/null +++ b/dist/global/can-observe.js @@ -0,0 +1,4543 @@ +/*[global-shim-start]*/ +(function(exports, global, doEval) { + // jshint ignore:line + var origDefine = global.define; + + var get = function(name) { + var parts = name.split("."), + cur = global, + i; + for (i = 0; i < parts.length; i++) { + if (!cur) { + break; + } + cur = cur[parts[i]]; + } + return cur; + }; + var set = function(name, val) { + var parts = name.split("."), + cur = global, + i, + part, + next; + for (i = 0; i < parts.length - 1; i++) { + part = parts[i]; + next = cur[part]; + if (!next) { + next = cur[part] = {}; + } + cur = next; + } + part = parts[parts.length - 1]; + cur[part] = val; + }; + var useDefault = function(mod) { + if (!mod || !mod.__esModule) return false; + var esProps = { __esModule: true, default: true }; + for (var p in mod) { + if (!esProps[p]) return false; + } + return true; + }; + + var hasCjsDependencies = function(deps) { + return ( + deps[0] === "require" && deps[1] === "exports" && deps[2] === "module" + ); + }; + + var modules = + (global.define && global.define.modules) || + (global._define && global._define.modules) || + {}; + var ourDefine = (global.define = function(moduleName, deps, callback) { + var module; + if (typeof deps === "function") { + callback = deps; + deps = []; + } + var args = [], + i; + for (i = 0; i < deps.length; i++) { + args.push( + exports[deps[i]] + ? get(exports[deps[i]]) + : modules[deps[i]] || get(deps[i]) + ); + } + // CJS has no dependencies but 3 callback arguments + if (hasCjsDependencies(deps) || (!deps.length && callback.length)) { + module = { exports: {} }; + args[0] = function(name) { + return exports[name] ? get(exports[name]) : modules[name]; + }; + args[1] = module.exports; + args[2] = module; + } else if (!args[0] && deps[0] === "exports") { + // Babel uses the exports and module object. + module = { exports: {} }; + args[0] = module.exports; + if (deps[1] === "module") { + args[1] = module; + } + } else if (!args[0] && deps[0] === "module") { + args[0] = { id: moduleName }; + } + + global.define = origDefine; + var result = callback ? callback.apply(null, args) : undefined; + global.define = ourDefine; + + // Favor CJS module.exports over the return value + result = module && module.exports ? module.exports : result; + modules[moduleName] = result; + + // Set global exports + var globalExport = exports[moduleName]; + if (globalExport && !get(globalExport)) { + if (useDefault(result)) { + result = result["default"]; + } + set(globalExport, result); + } + }); + global.define.orig = origDefine; + global.define.modules = modules; + global.define.amd = true; + ourDefine("@loader", [], function() { + // shim for @@global-helpers + var noop = function() {}; + return { + get: function() { + return { prepareGlobal: noop, retrieveGlobal: noop }; + }, + global: global, + __exec: function(__load) { + doEval(__load.source, global); + } + }; + }); +})( + { "can-util/namespace": "can" }, + typeof self == "object" && self.Object == Object ? self : window, + function(__$source__, __$global__) { + // jshint ignore:line + eval("(function() { " + __$source__ + " \n }).call(__$global__);"); + } +); + +/*can-namespace@1.0.0#can-namespace*/ +define('can-namespace', function (require, exports, module) { + module.exports = {}; +}); +/*can-symbol@1.6.0#can-symbol*/ +define('can-symbol', [ + 'require', + 'exports', + 'module', + 'can-namespace' +], function (require, exports, module) { + (function (global, require, exports, module) { + var namespace = require('can-namespace'); + var CanSymbol; + if (typeof Symbol !== 'undefined' && typeof Symbol.for === 'function') { + CanSymbol = Symbol; + } else { + var symbolNum = 0; + CanSymbol = function CanSymbolPolyfill(description) { + var symbolValue = '@@symbol' + symbolNum++ + description; + var symbol = {}; + Object.defineProperties(symbol, { + toString: { + value: function () { + return symbolValue; + } + } + }); + return symbol; + }; + var descriptionToSymbol = {}; + var symbolToDescription = {}; + CanSymbol.for = function (description) { + var symbol = descriptionToSymbol[description]; + if (!symbol) { + symbol = descriptionToSymbol[description] = CanSymbol(description); + symbolToDescription[symbol] = description; + } + return symbol; + }; + CanSymbol.keyFor = function (symbol) { + return symbolToDescription[symbol]; + }; + [ + 'hasInstance', + 'isConcatSpreadable', + 'iterator', + 'match', + 'prototype', + 'replace', + 'search', + 'species', + 'split', + 'toPrimitive', + 'toStringTag', + 'unscopables' + ].forEach(function (name) { + CanSymbol[name] = CanSymbol('Symbol.' + name); + }); + } + [ + 'isMapLike', + 'isListLike', + 'isValueLike', + 'isFunctionLike', + 'getOwnKeys', + 'getOwnKeyDescriptor', + 'proto', + 'getOwnEnumerableKeys', + 'hasOwnKey', + 'hasKey', + 'size', + 'getName', + 'getIdentity', + 'assignDeep', + 'updateDeep', + 'getValue', + 'setValue', + 'getKeyValue', + 'setKeyValue', + 'updateValues', + 'addValue', + 'removeValues', + 'apply', + 'new', + 'onValue', + 'offValue', + 'onKeyValue', + 'offKeyValue', + 'getKeyDependencies', + 'getValueDependencies', + 'keyHasDependencies', + 'valueHasDependencies', + 'onKeys', + 'onKeysAdded', + 'onKeysRemoved', + 'onPatches' + ].forEach(function (name) { + CanSymbol.for('can.' + name); + }); + module.exports = namespace.Symbol = CanSymbol; + }(function () { + return this; + }(), require, exports, module)); +}); +/*can-reflect@1.13.2#reflections/helpers*/ +define('can-reflect/reflections/helpers', [ + 'require', + 'exports', + 'module', + 'can-symbol' +], function (require, exports, module) { + var canSymbol = require('can-symbol'); + module.exports = { + makeGetFirstSymbolValue: function (symbolNames) { + var symbols = symbolNames.map(function (name) { + return canSymbol.for(name); + }); + var length = symbols.length; + return function getFirstSymbol(obj) { + var index = -1; + while (++index < length) { + if (obj[symbols[index]] !== undefined) { + return obj[symbols[index]]; + } + } + }; + }, + hasLength: function (list) { + var type = typeof list; + var length = list && type !== 'boolean' && typeof list !== 'number' && 'length' in list && list.length; + return typeof list !== 'function' && (length === 0 || typeof length === 'number' && length > 0 && length - 1 in list); + } + }; +}); +/*can-reflect@1.13.2#reflections/type/type*/ +define('can-reflect/reflections/type/type', [ + 'require', + 'exports', + 'module', + 'can-symbol', + 'can-reflect/reflections/helpers' +], function (require, exports, module) { + var canSymbol = require('can-symbol'); + var helpers = require('can-reflect/reflections/helpers'); + var plainFunctionPrototypePropertyNames = Object.getOwnPropertyNames(function () { + }.prototype); + var plainFunctionPrototypeProto = Object.getPrototypeOf(function () { + }.prototype); + function isConstructorLike(func) { + var value = func[canSymbol.for('can.new')]; + if (value !== undefined) { + return value; + } + if (typeof func !== 'function') { + return false; + } + var prototype = func.prototype; + if (!prototype) { + return false; + } + if (plainFunctionPrototypeProto !== Object.getPrototypeOf(prototype)) { + return true; + } + var propertyNames = Object.getOwnPropertyNames(prototype); + if (propertyNames.length === plainFunctionPrototypePropertyNames.length) { + for (var i = 0, len = propertyNames.length; i < len; i++) { + if (propertyNames[i] !== plainFunctionPrototypePropertyNames[i]) { + return true; + } + } + return false; + } else { + return true; + } + } + var getNewOrApply = helpers.makeGetFirstSymbolValue([ + 'can.new', + 'can.apply' + ]); + function isFunctionLike(obj) { + var result, symbolValue = obj[canSymbol.for('can.isFunctionLike')]; + if (symbolValue !== undefined) { + return symbolValue; + } + result = getNewOrApply(obj); + if (result !== undefined) { + return !!result; + } + return typeof obj === 'function'; + } + function isPrimitive(obj) { + var type = typeof obj; + if (obj == null || type !== 'function' && type !== 'object') { + return true; + } else { + return false; + } + } + function isBuiltIn(obj) { + if (isPrimitive(obj) || Array.isArray(obj) || isPlainObject(obj) || Object.prototype.toString.call(obj) !== '[object Object]' && Object.prototype.toString.call(obj).indexOf('[object ') !== -1) { + return true; + } else { + return false; + } + } + function isValueLike(obj) { + var symbolValue; + if (isPrimitive(obj)) { + return true; + } + symbolValue = obj[canSymbol.for('can.isValueLike')]; + if (typeof symbolValue !== 'undefined') { + return symbolValue; + } + var value = obj[canSymbol.for('can.getValue')]; + if (value !== undefined) { + return !!value; + } + } + function isMapLike(obj) { + if (isPrimitive(obj)) { + return false; + } + var isMapLike = obj[canSymbol.for('can.isMapLike')]; + if (typeof isMapLike !== 'undefined') { + return !!isMapLike; + } + var value = obj[canSymbol.for('can.getKeyValue')]; + if (value !== undefined) { + return !!value; + } + return true; + } + var onValueSymbol = canSymbol.for('can.onValue'), onKeyValueSymbol = canSymbol.for('can.onKeyValue'), onPatchesSymbol = canSymbol.for('can.onPatches'); + function isObservableLike(obj) { + if (isPrimitive(obj)) { + return false; + } + return Boolean(obj[onValueSymbol] || obj[onKeyValueSymbol] || obj[onPatchesSymbol]); + } + function isListLike(list) { + var symbolValue, type = typeof list; + if (type === 'string') { + return true; + } + if (isPrimitive(list)) { + return false; + } + symbolValue = list[canSymbol.for('can.isListLike')]; + if (typeof symbolValue !== 'undefined') { + return symbolValue; + } + var value = list[canSymbol.iterator]; + if (value !== undefined) { + return !!value; + } + if (Array.isArray(list)) { + return true; + } + return helpers.hasLength(list); + } + var supportsSymbols = typeof Symbol !== 'undefined' && typeof Symbol.for === 'function'; + var isSymbolLike; + if (supportsSymbols) { + isSymbolLike = function (symbol) { + return typeof symbol === 'symbol'; + }; + } else { + var symbolStart = '@@symbol'; + isSymbolLike = function (symbol) { + if (typeof symbol === 'object' && !Array.isArray(symbol)) { + return symbol.toString().substr(0, symbolStart.length) === symbolStart; + } else { + return false; + } + }; + } + var coreHasOwn = Object.prototype.hasOwnProperty; + var funcToString = Function.prototype.toString; + var objectCtorString = funcToString.call(Object); + function isPlainObject(obj) { + if (!obj || typeof obj !== 'object') { + return false; + } + var proto = Object.getPrototypeOf(obj); + if (proto === Object.prototype || proto === null) { + return true; + } + var Constructor = coreHasOwn.call(proto, 'constructor') && proto.constructor; + return typeof Constructor === 'function' && Constructor instanceof Constructor && funcToString.call(Constructor) === objectCtorString; + } + module.exports = { + isConstructorLike: isConstructorLike, + isFunctionLike: isFunctionLike, + isListLike: isListLike, + isMapLike: isMapLike, + isObservableLike: isObservableLike, + isPrimitive: isPrimitive, + isBuiltIn: isBuiltIn, + isValueLike: isValueLike, + isSymbolLike: isSymbolLike, + isMoreListLikeThanMapLike: function (obj) { + if (Array.isArray(obj)) { + return true; + } + if (obj instanceof Array) { + return true; + } + var value = obj[canSymbol.for('can.isMoreListLikeThanMapLike')]; + if (value !== undefined) { + return value; + } + var isListLike = this.isListLike(obj), isMapLike = this.isMapLike(obj); + if (isListLike && !isMapLike) { + return true; + } else if (!isListLike && isMapLike) { + return false; + } + }, + isIteratorLike: function (obj) { + return obj && typeof obj === 'object' && typeof obj.next === 'function' && obj.next.length === 0; + }, + isPromise: function (obj) { + return obj instanceof Promise || Object.prototype.toString.call(obj) === '[object Promise]'; + }, + isPlainObject: isPlainObject + }; +}); +/*can-reflect@1.13.2#reflections/call/call*/ +define('can-reflect/reflections/call/call', [ + 'require', + 'exports', + 'module', + 'can-symbol', + 'can-reflect/reflections/type/type' +], function (require, exports, module) { + var canSymbol = require('can-symbol'); + var typeReflections = require('can-reflect/reflections/type/type'); + module.exports = { + call: function (func, context) { + var args = [].slice.call(arguments, 2); + var apply = func[canSymbol.for('can.apply')]; + if (apply) { + return apply.call(func, context, args); + } else { + return func.apply(context, args); + } + }, + apply: function (func, context, args) { + var apply = func[canSymbol.for('can.apply')]; + if (apply) { + return apply.call(func, context, args); + } else { + return func.apply(context, args); + } + }, + 'new': function (func) { + var args = [].slice.call(arguments, 1); + var makeNew = func[canSymbol.for('can.new')]; + if (makeNew) { + return makeNew.apply(func, args); + } else { + var context = Object.create(func.prototype); + var ret = func.apply(context, args); + if (typeReflections.isPrimitive(ret)) { + return context; + } else { + return ret; + } + } + } + }; +}); +/*can-reflect@1.13.2#reflections/get-set/get-set*/ +define('can-reflect/reflections/get-set/get-set', [ + 'require', + 'exports', + 'module', + 'can-symbol', + 'can-reflect/reflections/type/type' +], function (require, exports, module) { + var canSymbol = require('can-symbol'); + var typeReflections = require('can-reflect/reflections/type/type'); + var setKeyValueSymbol = canSymbol.for('can.setKeyValue'), getKeyValueSymbol = canSymbol.for('can.getKeyValue'), getValueSymbol = canSymbol.for('can.getValue'), setValueSymbol = canSymbol.for('can.setValue'); + var reflections = { + setKeyValue: function (obj, key, value) { + if (typeReflections.isSymbolLike(key)) { + if (typeof key === 'symbol') { + obj[key] = value; + } else { + Object.defineProperty(obj, key, { + enumerable: false, + configurable: true, + value: value, + writable: true + }); + } + return; + } + var setKeyValue = obj[setKeyValueSymbol]; + if (setKeyValue !== undefined) { + return setKeyValue.call(obj, key, value); + } else { + obj[key] = value; + } + }, + getKeyValue: function (obj, key) { + var getKeyValue = obj[getKeyValueSymbol]; + if (getKeyValue) { + return getKeyValue.call(obj, key); + } + return obj[key]; + }, + deleteKeyValue: function (obj, key) { + var deleteKeyValue = obj[canSymbol.for('can.deleteKeyValue')]; + if (deleteKeyValue) { + return deleteKeyValue.call(obj, key); + } + delete obj[key]; + }, + getValue: function (value) { + if (typeReflections.isPrimitive(value)) { + return value; + } + var getValue = value[getValueSymbol]; + if (getValue) { + return getValue.call(value); + } + return value; + }, + setValue: function (item, value) { + var setValue = item && item[setValueSymbol]; + if (setValue) { + return setValue.call(item, value); + } else { + throw new Error('can-reflect.setValue - Can not set value.'); + } + }, + splice: function (obj, index, removing, adding) { + var howMany; + if (typeof removing !== 'number') { + var updateValues = obj[canSymbol.for('can.updateValues')]; + if (updateValues) { + return updateValues.call(obj, index, removing, adding); + } + howMany = removing.length; + } else { + howMany = removing; + } + var splice = obj[canSymbol.for('can.splice')]; + if (splice) { + return splice.call(obj, index, howMany, adding); + } + return [].splice.apply(obj, [ + index, + howMany + ].concat(adding)); + }, + addValues: function (obj, adding, index) { + var add = obj[canSymbol.for('can.addValues')]; + if (add) { + return add.call(obj, adding, index); + } + if (Array.isArray(obj) && index === undefined) { + return obj.push.apply(obj, adding); + } + return reflections.splice(obj, index, [], adding); + }, + removeValues: function (obj, removing, index) { + var removeValues = obj[canSymbol.for('can.removeValues')]; + if (removeValues) { + return removeValues.call(obj, removing, index); + } + if (Array.isArray(obj) && index === undefined) { + removing.forEach(function (item) { + var index = obj.indexOf(item); + if (index >= 0) { + obj.splice(index, 1); + } + }); + return; + } + return reflections.splice(obj, index, removing, []); + } + }; + reflections.get = reflections.getKeyValue; + reflections.set = reflections.setKeyValue; + reflections['delete'] = reflections.deleteKeyValue; + module.exports = reflections; +}); +/*can-reflect@1.13.2#reflections/observe/observe*/ +define('can-reflect/reflections/observe/observe', [ + 'require', + 'exports', + 'module', + 'can-symbol' +], function (require, exports, module) { + var canSymbol = require('can-symbol'); + var slice = [].slice; + function makeFallback(symbolName, fallbackName) { + return function (obj, event, handler, queueName) { + var method = obj[canSymbol.for(symbolName)]; + if (method !== undefined) { + return method.call(obj, event, handler, queueName); + } + return this[fallbackName].apply(this, arguments); + }; + } + function makeErrorIfMissing(symbolName, errorMessage) { + return function (obj) { + var method = obj[canSymbol.for(symbolName)]; + if (method !== undefined) { + var args = slice.call(arguments, 1); + return method.apply(obj, args); + } + throw new Error(errorMessage); + }; + } + module.exports = { + onKeyValue: makeFallback('can.onKeyValue', 'onEvent'), + offKeyValue: makeFallback('can.offKeyValue', 'offEvent'), + onKeys: makeErrorIfMissing('can.onKeys', 'can-reflect: can not observe an onKeys event'), + onKeysAdded: makeErrorIfMissing('can.onKeysAdded', 'can-reflect: can not observe an onKeysAdded event'), + onKeysRemoved: makeErrorIfMissing('can.onKeysRemoved', 'can-reflect: can not unobserve an onKeysRemoved event'), + getKeyDependencies: makeErrorIfMissing('can.getKeyDependencies', 'can-reflect: can not determine dependencies'), + getWhatIChange: makeErrorIfMissing('can.getWhatIChange', 'can-reflect: can not determine dependencies'), + getChangesDependencyRecord: function getChangesDependencyRecord(handler) { + var fn = handler[canSymbol.for('can.getChangesDependencyRecord')]; + if (typeof fn === 'function') { + return fn(); + } + }, + keyHasDependencies: makeErrorIfMissing('can.keyHasDependencies', 'can-reflect: can not determine if this has key dependencies'), + onValue: makeErrorIfMissing('can.onValue', 'can-reflect: can not observe value change'), + offValue: makeErrorIfMissing('can.offValue', 'can-reflect: can not unobserve value change'), + getValueDependencies: makeErrorIfMissing('can.getValueDependencies', 'can-reflect: can not determine dependencies'), + valueHasDependencies: makeErrorIfMissing('can.valueHasDependencies', 'can-reflect: can not determine if value has dependencies'), + onPatches: makeErrorIfMissing('can.onPatches', 'can-reflect: can not observe patches on object'), + offPatches: makeErrorIfMissing('can.offPatches', 'can-reflect: can not unobserve patches on object'), + onInstancePatches: makeErrorIfMissing('can.onInstancePatches', 'can-reflect: can not observe onInstancePatches on Type'), + offInstancePatches: makeErrorIfMissing('can.offInstancePatches', 'can-reflect: can not unobserve onInstancePatches on Type'), + onInstanceBoundChange: makeErrorIfMissing('can.onInstanceBoundChange', 'can-reflect: can not observe bound state change in instances.'), + offInstanceBoundChange: makeErrorIfMissing('can.offInstanceBoundChange', 'can-reflect: can not unobserve bound state change'), + isBound: makeErrorIfMissing('can.isBound', 'can-reflect: cannot determine if object is bound'), + onEvent: function (obj, eventName, callback, queue) { + if (obj) { + var onEvent = obj[canSymbol.for('can.onEvent')]; + if (onEvent !== undefined) { + return onEvent.call(obj, eventName, callback, queue); + } else if (obj.addEventListener) { + obj.addEventListener(eventName, callback, queue); + } + } + }, + offEvent: function (obj, eventName, callback, queue) { + if (obj) { + var offEvent = obj[canSymbol.for('can.offEvent')]; + if (offEvent !== undefined) { + return offEvent.call(obj, eventName, callback, queue); + } else if (obj.removeEventListener) { + obj.removeEventListener(eventName, callback, queue); + } + } + }, + setPriority: function (obj, priority) { + if (obj) { + var setPriority = obj[canSymbol.for('can.setPriority')]; + if (setPriority !== undefined) { + setPriority.call(obj, priority); + return true; + } + } + return false; + }, + getPriority: function (obj) { + if (obj) { + var getPriority = obj[canSymbol.for('can.getPriority')]; + if (getPriority !== undefined) { + return getPriority.call(obj); + } + } + return undefined; + } + }; +}); +/*can-reflect@1.13.2#reflections/shape/shape*/ +define('can-reflect/reflections/shape/shape', [ + 'require', + 'exports', + 'module', + 'can-symbol', + 'can-reflect/reflections/get-set/get-set', + 'can-reflect/reflections/type/type', + 'can-reflect/reflections/helpers' +], function (require, exports, module) { + var canSymbol = require('can-symbol'); + var getSetReflections = require('can-reflect/reflections/get-set/get-set'); + var typeReflections = require('can-reflect/reflections/type/type'); + var helpers = require('can-reflect/reflections/helpers'); + var ArrayMap; + if (typeof Map === 'function') { + ArrayMap = Map; + } else { + function isEven(num) { + return !(num % 2); + } + ArrayMap = function () { + this.contents = []; + }; + ArrayMap.prototype = { + _getIndex: function (key) { + var idx; + do { + idx = this.contents.indexOf(key, idx); + } while (idx !== -1 && !isEven(idx)); + return idx; + }, + has: function (key) { + return this._getIndex(key) !== -1; + }, + get: function (key) { + var idx = this._getIndex(key); + if (idx !== -1) { + return this.contents[idx + 1]; + } + }, + set: function (key, value) { + var idx = this._getIndex(key); + if (idx !== -1) { + this.contents[idx + 1] = value; + } else { + this.contents.push(key); + this.contents.push(value); + } + } + }; + } + var shapeReflections; + var shiftFirstArgumentToThis = function (func) { + return function () { + var args = [this]; + args.push.apply(args, arguments); + return func.apply(null, args); + }; + }; + var getKeyValueSymbol = canSymbol.for('can.getKeyValue'); + var shiftedGetKeyValue = shiftFirstArgumentToThis(getSetReflections.getKeyValue); + var setKeyValueSymbol = canSymbol.for('can.setKeyValue'); + var shiftedSetKeyValue = shiftFirstArgumentToThis(getSetReflections.setKeyValue); + var sizeSymbol = canSymbol.for('can.size'); + var serializeMap = null; + var hasUpdateSymbol = helpers.makeGetFirstSymbolValue([ + 'can.updateDeep', + 'can.assignDeep', + 'can.setKeyValue' + ]); + var shouldUpdateOrAssign = function (obj) { + return typeReflections.isPlainObject(obj) || Array.isArray(obj) || !!hasUpdateSymbol(obj); + }; + function isSerializable(obj) { + if (typeReflections.isPrimitive(obj)) { + return true; + } + if (hasUpdateSymbol(obj)) { + return false; + } + return typeReflections.isBuiltIn(obj) && !typeReflections.isPlainObject(obj); + } + var Object_Keys; + try { + Object.keys(1); + Object_Keys = Object.keys; + } catch (e) { + Object_Keys = function (obj) { + if (typeReflections.isPrimitive(obj)) { + return []; + } else { + return Object.keys(obj); + } + }; + } + function makeSerializer(methodName, symbolsToCheck) { + return function serializer(value, MapType) { + if (isSerializable(value)) { + return value; + } + var firstSerialize; + if (!serializeMap) { + serializeMap = { + unwrap: MapType ? new MapType() : new ArrayMap(), + serialize: MapType ? new MapType() : new ArrayMap() + }; + firstSerialize = true; + } + var serialized; + if (typeReflections.isValueLike(value)) { + serialized = this[methodName](getSetReflections.getValue(value)); + } else { + var isListLike = typeReflections.isIteratorLike(value) || typeReflections.isMoreListLikeThanMapLike(value); + serialized = isListLike ? [] : {}; + if (serializeMap) { + if (serializeMap[methodName].has(value)) { + return serializeMap[methodName].get(value); + } else { + serializeMap[methodName].set(value, serialized); + } + } + for (var i = 0, len = symbolsToCheck.length; i < len; i++) { + var serializer = value[symbolsToCheck[i]]; + if (serializer) { + var result = serializer.call(value, serialized); + if (firstSerialize) { + serializeMap = null; + } + return result; + } + } + if (typeof obj === 'function') { + if (serializeMap) { + serializeMap[methodName].set(value, value); + } + serialized = value; + } else if (isListLike) { + this.eachIndex(value, function (childValue, index) { + serialized[index] = this[methodName](childValue); + }, this); + } else { + this.eachKey(value, function (childValue, prop) { + serialized[prop] = this[methodName](childValue); + }, this); + } + } + if (firstSerialize) { + serializeMap = null; + } + return serialized; + }; + } + var makeMap; + if (typeof Map !== 'undefined') { + makeMap = function (keys) { + var map = new Map(); + shapeReflections.eachIndex(keys, function (key) { + map.set(key, true); + }); + return map; + }; + } else { + makeMap = function (keys) { + var map = {}; + keys.forEach(function (key) { + map[key] = true; + }); + return { + get: function (key) { + return map[key]; + }, + set: function (key, value) { + map[key] = value; + }, + keys: function () { + return keys; + } + }; + }; + } + var fastHasOwnKey = function (obj) { + var hasOwnKey = obj[canSymbol.for('can.hasOwnKey')]; + if (hasOwnKey) { + return hasOwnKey.bind(obj); + } else { + var map = makeMap(shapeReflections.getOwnEnumerableKeys(obj)); + return function (key) { + return map.get(key); + }; + } + }; + function addPatch(patches, patch) { + var lastPatch = patches[patches.length - 1]; + if (lastPatch) { + if (lastPatch.deleteCount === lastPatch.insert.length && patch.index - lastPatch.index === lastPatch.deleteCount) { + lastPatch.insert.push.apply(lastPatch.insert, patch.insert); + lastPatch.deleteCount += patch.deleteCount; + return; + } + } + patches.push(patch); + } + function updateDeepList(target, source, isAssign) { + var sourceArray = this.toArray(source); + var patches = [], lastIndex = -1; + this.eachIndex(target, function (curVal, index) { + lastIndex = index; + if (index >= sourceArray.length) { + if (!isAssign) { + addPatch(patches, { + index: index, + deleteCount: target.length - index + 1, + insert: [] + }); + } + return false; + } + var newVal = sourceArray[index]; + if (typeReflections.isPrimitive(curVal) || typeReflections.isPrimitive(newVal) || shouldUpdateOrAssign(curVal) === false) { + addPatch(patches, { + index: index, + deleteCount: 1, + insert: [newVal] + }); + } else { + this.updateDeep(curVal, newVal); + } + }, this); + if (sourceArray.length > lastIndex) { + addPatch(patches, { + index: lastIndex + 1, + deleteCount: 0, + insert: sourceArray.slice(lastIndex + 1) + }); + } + for (var i = 0, patchLen = patches.length; i < patchLen; i++) { + var patch = patches[i]; + getSetReflections.splice(target, patch.index, patch.deleteCount, patch.insert); + } + return target; + } + shapeReflections = { + each: function (obj, callback, context) { + if (typeReflections.isIteratorLike(obj) || typeReflections.isMoreListLikeThanMapLike(obj)) { + return this.eachIndex(obj, callback, context); + } else { + return this.eachKey(obj, callback, context); + } + }, + eachIndex: function (list, callback, context) { + if (Array.isArray(list)) { + return this.eachListLike(list, callback, context); + } else { + var iter, iterator = list[canSymbol.iterator]; + if (typeReflections.isIteratorLike(list)) { + iter = list; + } else if (iterator) { + iter = iterator.call(list); + } + if (iter) { + var res, index = 0; + while (!(res = iter.next()).done) { + if (callback.call(context || list, res.value, index++, list) === false) { + break; + } + } + } else { + this.eachListLike(list, callback, context); + } + } + return list; + }, + eachListLike: function (list, callback, context) { + var index = -1; + var length = list.length; + if (length === undefined) { + var size = list[sizeSymbol]; + if (size) { + length = size.call(list); + } else { + throw new Error('can-reflect: unable to iterate.'); + } + } + while (++index < length) { + var item = list[index]; + if (callback.call(context || item, item, index, list) === false) { + break; + } + } + return list; + }, + toArray: function (obj) { + var arr = []; + this.each(obj, function (value) { + arr.push(value); + }); + return arr; + }, + eachKey: function (obj, callback, context) { + if (obj) { + var enumerableKeys = this.getOwnEnumerableKeys(obj); + var getKeyValue = obj[getKeyValueSymbol] || shiftedGetKeyValue; + return this.eachIndex(enumerableKeys, function (key) { + var value = getKeyValue.call(obj, key); + return callback.call(context || obj, value, key, obj); + }); + } + return obj; + }, + 'hasOwnKey': function (obj, key) { + var hasOwnKey = obj[canSymbol.for('can.hasOwnKey')]; + if (hasOwnKey) { + return hasOwnKey.call(obj, key); + } + var getOwnKeys = obj[canSymbol.for('can.getOwnKeys')]; + if (getOwnKeys) { + var found = false; + this.eachIndex(getOwnKeys.call(obj), function (objKey) { + if (objKey === key) { + found = true; + return false; + } + }); + return found; + } + return obj.hasOwnProperty(key); + }, + getOwnEnumerableKeys: function (obj) { + var getOwnEnumerableKeys = obj[canSymbol.for('can.getOwnEnumerableKeys')]; + if (getOwnEnumerableKeys) { + return getOwnEnumerableKeys.call(obj); + } + if (obj[canSymbol.for('can.getOwnKeys')] && obj[canSymbol.for('can.getOwnKeyDescriptor')]) { + var keys = []; + this.eachIndex(this.getOwnKeys(obj), function (key) { + var descriptor = this.getOwnKeyDescriptor(obj, key); + if (descriptor.enumerable) { + keys.push(key); + } + }, this); + return keys; + } else { + return Object_Keys(obj); + } + }, + getOwnKeys: function (obj) { + var getOwnKeys = obj[canSymbol.for('can.getOwnKeys')]; + if (getOwnKeys) { + return getOwnKeys.call(obj); + } else { + return Object.getOwnPropertyNames(obj); + } + }, + getOwnKeyDescriptor: function (obj, key) { + var getOwnKeyDescriptor = obj[canSymbol.for('can.getOwnKeyDescriptor')]; + if (getOwnKeyDescriptor) { + return getOwnKeyDescriptor.call(obj, key); + } else { + return Object.getOwnPropertyDescriptor(obj, key); + } + }, + unwrap: makeSerializer('unwrap', [canSymbol.for('can.unwrap')]), + serialize: makeSerializer('serialize', [ + canSymbol.for('can.serialize'), + canSymbol.for('can.unwrap') + ]), + assignMap: function (target, source) { + var hasOwnKey = fastHasOwnKey(target); + var getKeyValue = target[getKeyValueSymbol] || shiftedGetKeyValue; + var setKeyValue = target[setKeyValueSymbol] || shiftedSetKeyValue; + this.eachKey(source, function (value, key) { + if (!hasOwnKey(key) || getKeyValue.call(target, key) !== value) { + setKeyValue.call(target, key, value); + } + }); + return target; + }, + assignList: function (target, source) { + var inserting = this.toArray(source); + getSetReflections.splice(target, 0, inserting, inserting); + return target; + }, + assign: function (target, source) { + if (typeReflections.isIteratorLike(source) || typeReflections.isMoreListLikeThanMapLike(source)) { + this.assignList(target, source); + } else { + this.assignMap(target, source); + } + return target; + }, + assignDeepMap: function (target, source) { + var hasOwnKey = fastHasOwnKey(target); + var getKeyValue = target[getKeyValueSymbol] || shiftedGetKeyValue; + var setKeyValue = target[setKeyValueSymbol] || shiftedSetKeyValue; + this.eachKey(source, function (newVal, key) { + if (!hasOwnKey(key)) { + getSetReflections.setKeyValue(target, key, newVal); + } else { + var curVal = getKeyValue.call(target, key); + if (newVal === curVal) { + } else if (typeReflections.isPrimitive(curVal) || typeReflections.isPrimitive(newVal) || shouldUpdateOrAssign(curVal) === false) { + setKeyValue.call(target, key, newVal); + } else { + this.assignDeep(curVal, newVal); + } + } + }, this); + return target; + }, + assignDeepList: function (target, source) { + return updateDeepList.call(this, target, source, true); + }, + assignDeep: function (target, source) { + var assignDeep = target[canSymbol.for('can.assignDeep')]; + if (assignDeep) { + assignDeep.call(target, source); + } else if (typeReflections.isMoreListLikeThanMapLike(source)) { + this.assignDeepList(target, source); + } else { + this.assignDeepMap(target, source); + } + return target; + }, + updateMap: function (target, source) { + var sourceKeyMap = makeMap(this.getOwnEnumerableKeys(source)); + var sourceGetKeyValue = source[getKeyValueSymbol] || shiftedGetKeyValue; + var targetSetKeyValue = target[setKeyValueSymbol] || shiftedSetKeyValue; + this.eachKey(target, function (curVal, key) { + if (!sourceKeyMap.get(key)) { + getSetReflections.deleteKeyValue(target, key); + return; + } + sourceKeyMap.set(key, false); + var newVal = sourceGetKeyValue.call(source, key); + if (newVal !== curVal) { + targetSetKeyValue.call(target, key, newVal); + } + }, this); + this.eachIndex(sourceKeyMap.keys(), function (key) { + if (sourceKeyMap.get(key)) { + targetSetKeyValue.call(target, key, sourceGetKeyValue.call(source, key)); + } + }); + return target; + }, + updateList: function (target, source) { + var inserting = this.toArray(source); + getSetReflections.splice(target, 0, target, inserting); + return target; + }, + update: function (target, source) { + if (typeReflections.isIteratorLike(source) || typeReflections.isMoreListLikeThanMapLike(source)) { + this.updateList(target, source); + } else { + this.updateMap(target, source); + } + return target; + }, + updateDeepMap: function (target, source) { + var sourceKeyMap = makeMap(this.getOwnEnumerableKeys(source)); + var sourceGetKeyValue = source[getKeyValueSymbol] || shiftedGetKeyValue; + var targetSetKeyValue = target[setKeyValueSymbol] || shiftedSetKeyValue; + this.eachKey(target, function (curVal, key) { + if (!sourceKeyMap.get(key)) { + getSetReflections.deleteKeyValue(target, key); + return; + } + sourceKeyMap.set(key, false); + var newVal = sourceGetKeyValue.call(source, key); + if (typeReflections.isPrimitive(curVal) || typeReflections.isPrimitive(newVal) || shouldUpdateOrAssign(curVal) === false) { + targetSetKeyValue.call(target, key, newVal); + } else { + this.updateDeep(curVal, newVal); + } + }, this); + this.eachIndex(sourceKeyMap.keys(), function (key) { + if (sourceKeyMap.get(key)) { + targetSetKeyValue.call(target, key, sourceGetKeyValue.call(source, key)); + } + }); + return target; + }, + updateDeepList: function (target, source) { + return updateDeepList.call(this, target, source); + }, + updateDeep: function (target, source) { + var updateDeep = target[canSymbol.for('can.updateDeep')]; + if (updateDeep) { + updateDeep.call(target, source); + } else if (typeReflections.isMoreListLikeThanMapLike(source)) { + this.updateDeepList(target, source); + } else { + this.updateDeepMap(target, source); + } + return target; + }, + 'hasKey': function (obj, key) { + var hasKey = obj[canSymbol.for('can.hasKey')]; + if (hasKey) { + return hasKey.call(obj, key); + } + var found = shapeReflections.hasOwnKey(obj, key); + return found || key in obj; + }, + getAllEnumerableKeys: function () { + }, + getAllKeys: function () { + }, + assignSymbols: function (target, source) { + this.eachKey(source, function (value, key) { + var symbol = typeReflections.isSymbolLike(canSymbol[key]) ? canSymbol[key] : canSymbol.for(key); + getSetReflections.setKeyValue(target, symbol, value); + }); + return target; + }, + isSerializable: isSerializable, + size: function (obj) { + var size = obj[sizeSymbol]; + var count = 0; + if (size) { + return size.call(obj); + } else if (helpers.hasLength(obj)) { + return obj.length; + } else if (typeReflections.isListLike(obj)) { + this.each(obj, function () { + count++; + }); + return count; + } else if (obj) { + for (var prop in obj) { + if (obj.hasOwnProperty(prop)) { + count++; + } + } + return count; + } else { + return undefined; + } + }, + defineInstanceKey: function (cls, key, properties) { + var defineInstanceKey = cls[canSymbol.for('can.defineInstanceKey')]; + if (defineInstanceKey) { + return defineInstanceKey.call(cls, key, properties); + } + var proto = cls.prototype; + defineInstanceKey = proto[canSymbol.for('can.defineInstanceKey')]; + if (defineInstanceKey) { + defineInstanceKey.call(proto, key, properties); + } else { + Object.defineProperty(proto, key, shapeReflections.assign({ + configurable: true, + enumerable: !typeReflections.isSymbolLike(key), + writable: true + }, properties)); + } + } + }; + shapeReflections.keys = shapeReflections.getOwnEnumerableKeys; + module.exports = shapeReflections; +}); +/*can-reflect@1.13.2#reflections/get-name/get-name*/ +define('can-reflect/reflections/get-name/get-name', [ + 'require', + 'exports', + 'module', + 'can-symbol', + 'can-reflect/reflections/type/type' +], function (require, exports, module) { + var canSymbol = require('can-symbol'); + var typeReflections = require('can-reflect/reflections/type/type'); + var getNameSymbol = canSymbol.for('can.getName'); + function setName(obj, nameGetter) { + if (typeof nameGetter !== 'function') { + var value = nameGetter; + nameGetter = function () { + return value; + }; + } + Object.defineProperty(obj, getNameSymbol, { value: nameGetter }); + } + function getName(obj) { + var nameGetter = obj[getNameSymbol]; + if (nameGetter) { + return nameGetter.call(obj); + } + if (typeof obj === 'function') { + return obj.name; + } + if (obj.constructor && obj !== obj.constructor) { + var parent = getName(obj.constructor); + if (parent) { + if (typeReflections.isValueLike(obj)) { + return parent + '<>'; + } + if (typeReflections.isMoreListLikeThanMapLike(obj)) { + return parent + '[]'; + } + if (typeReflections.isMapLike(obj)) { + return parent + '{}'; + } + } + } + return undefined; + } + module.exports = { + setName: setName, + getName: getName + }; +}); +/*can-reflect@1.13.2#types/map*/ +define('can-reflect/types/map', [ + 'require', + 'exports', + 'module', + 'can-reflect/reflections/shape/shape', + 'can-symbol' +], function (require, exports, module) { + var shape = require('can-reflect/reflections/shape/shape'); + var CanSymbol = require('can-symbol'); + function keysPolyfill() { + var keys = []; + var currentIndex = 0; + this.forEach(function (val, key) { + keys.push(key); + }); + return { + next: function () { + return { + value: keys[currentIndex], + done: currentIndex++ === keys.length + }; + } + }; + } + if (typeof Map !== 'undefined') { + shape.assignSymbols(Map.prototype, { + 'can.getOwnEnumerableKeys': Map.prototype.keys, + 'can.setKeyValue': Map.prototype.set, + 'can.getKeyValue': Map.prototype.get, + 'can.deleteKeyValue': Map.prototype['delete'], + 'can.hasOwnKey': Map.prototype.has + }); + if (typeof Map.prototype.keys !== 'function') { + Map.prototype.keys = Map.prototype[CanSymbol.for('can.getOwnEnumerableKeys')] = keysPolyfill; + } + } + if (typeof WeakMap !== 'undefined') { + shape.assignSymbols(WeakMap.prototype, { + 'can.getOwnEnumerableKeys': function () { + throw new Error('can-reflect: WeakMaps do not have enumerable keys.'); + }, + 'can.setKeyValue': WeakMap.prototype.set, + 'can.getKeyValue': WeakMap.prototype.get, + 'can.deleteKeyValue': WeakMap.prototype['delete'], + 'can.hasOwnKey': WeakMap.prototype.has + }); + } +}); +/*can-reflect@1.13.2#types/set*/ +define('can-reflect/types/set', [ + 'require', + 'exports', + 'module', + 'can-reflect/reflections/shape/shape', + 'can-symbol' +], function (require, exports, module) { + var shape = require('can-reflect/reflections/shape/shape'); + var CanSymbol = require('can-symbol'); + if (typeof Set !== 'undefined') { + shape.assignSymbols(Set.prototype, { + 'can.isMoreListLikeThanMapLike': true, + 'can.updateValues': function (index, removing, adding) { + if (removing !== adding) { + shape.each(removing, function (value) { + this.delete(value); + }, this); + } + shape.each(adding, function (value) { + this.add(value); + }, this); + }, + 'can.size': function () { + return this.size; + } + }); + if (typeof Set.prototype[CanSymbol.iterator] !== 'function') { + Set.prototype[CanSymbol.iterator] = function () { + var arr = []; + var currentIndex = 0; + this.forEach(function (val) { + arr.push(val); + }); + return { + next: function () { + return { + value: arr[currentIndex], + done: currentIndex++ === arr.length + }; + } + }; + }; + } + } + if (typeof WeakSet !== 'undefined') { + shape.assignSymbols(WeakSet.prototype, { + 'can.isListLike': true, + 'can.isMoreListLikeThanMapLike': true, + 'can.updateValues': function (index, removing, adding) { + if (removing !== adding) { + shape.each(removing, function (value) { + this.delete(value); + }, this); + } + shape.each(adding, function (value) { + this.add(value); + }, this); + }, + 'can.size': function () { + throw new Error('can-reflect: WeakSets do not have enumerable keys.'); + } + }); + } +}); +/*can-reflect@1.13.2#can-reflect*/ +define('can-reflect', [ + 'require', + 'exports', + 'module', + 'can-reflect/reflections/call/call', + 'can-reflect/reflections/get-set/get-set', + 'can-reflect/reflections/observe/observe', + 'can-reflect/reflections/shape/shape', + 'can-reflect/reflections/type/type', + 'can-reflect/reflections/get-name/get-name', + 'can-namespace', + 'can-reflect/types/map', + 'can-reflect/types/set' +], function (require, exports, module) { + var functionReflections = require('can-reflect/reflections/call/call'); + var getSet = require('can-reflect/reflections/get-set/get-set'); + var observe = require('can-reflect/reflections/observe/observe'); + var shape = require('can-reflect/reflections/shape/shape'); + var type = require('can-reflect/reflections/type/type'); + var getName = require('can-reflect/reflections/get-name/get-name'); + var namespace = require('can-namespace'); + var reflect = {}; + [ + functionReflections, + getSet, + observe, + shape, + type, + getName + ].forEach(function (reflections) { + for (var prop in reflections) { + reflect[prop] = reflections[prop]; + } + }); + require('can-reflect/types/map'); + require('can-reflect/types/set'); + module.exports = namespace.Reflect = reflect; +}); +/*can-observation-recorder@1.0.1#can-observation-recorder*/ +define('can-observation-recorder', [ + 'require', + 'exports', + 'module', + 'can-namespace' +], function (require, exports, module) { + var namespace = require('can-namespace'); + var stack = []; + var ObservationRecorder = { + stack: stack, + start: function () { + var deps = { + keyDependencies: new Map(), + valueDependencies: new Set(), + traps: null, + ignore: 0 + }; + stack.push(deps); + return deps; + }, + stop: function () { + return stack.pop(); + }, + add: function (obj, event) { + var top = stack[stack.length - 1]; + if (top && top.ignore === 0) { + if (top.traps) { + top.traps.push([ + obj, + event + ]); + } else { + if (event === undefined) { + top.valueDependencies.add(obj); + } else { + var eventSet = top.keyDependencies.get(obj); + if (!eventSet) { + eventSet = new Set(); + top.keyDependencies.set(obj, eventSet); + } + eventSet.add(event); + } + } + } + }, + addMany: function (observes) { + var top = stack[stack.length - 1]; + if (top) { + if (top.traps) { + top.traps.push.apply(top.traps, observes); + } else { + for (var i = 0, len = observes.length; i < len; i++) { + this.add(observes[i][0], observes[i][1]); + } + } + } + }, + ignore: function (fn) { + return function () { + if (stack.length) { + var top = stack[stack.length - 1]; + top.ignore++; + var res = fn.apply(this, arguments); + top.ignore--; + return res; + } else { + return fn.apply(this, arguments); + } + }; + }, + isRecording: function () { + var len = stack.length; + var last = len && stack[len - 1]; + return last && last.ignore === 0 && last; + }, + makeDependenciesRecord: function () { + return { + traps: null, + keyDependencies: new Map(), + valueDependencies: new Set(), + ignore: 0 + }; + }, + makeDependenciesRecorder: function () { + return ObservationRecorder.makeDependenciesRecord(); + }, + trap: function () { + if (stack.length) { + var top = stack[stack.length - 1]; + var oldTraps = top.traps; + var traps = top.traps = []; + return function () { + top.traps = oldTraps; + return traps; + }; + } else { + return function () { + return []; + }; + } + }, + trapsCount: function () { + if (stack.length) { + var top = stack[stack.length - 1]; + return top.traps.length; + } else { + return 0; + } + } + }; + if (namespace.ObservationRecorder) { + throw new Error('You can\'t have two versions of can-observation-recorder, check your dependencies'); + } else { + module.exports = namespace.ObservationRecorder = ObservationRecorder; + } +}); +/*can-log@1.0.0#can-log*/ +define('can-log', function (require, exports, module) { + 'use strict'; + exports.warnTimeout = 5000; + exports.logLevel = 0; + exports.warn = function () { + var ll = this.logLevel; + if (ll < 2) { + if (typeof console !== 'undefined' && console.warn) { + this._logger('warn', Array.prototype.slice.call(arguments)); + } else if (typeof console !== 'undefined' && console.log) { + this._logger('log', Array.prototype.slice.call(arguments)); + } + } + }; + exports.log = function () { + var ll = this.logLevel; + if (ll < 1) { + if (typeof console !== 'undefined' && console.log) { + this._logger('log', Array.prototype.slice.call(arguments)); + } + } + }; + exports.error = function () { + var ll = this.logLevel; + if (ll < 1) { + if (typeof console !== 'undefined' && console.error) { + this._logger('error', Array.prototype.slice.call(arguments)); + } + } + }; + exports._logger = function (type, arr) { + try { + console[type].apply(console, arr); + } catch (e) { + console[type](arr); + } + }; +}); +/*can-log@1.0.0#dev/dev*/ +define('can-log/dev/dev', [ + 'require', + 'exports', + 'module', + 'can-log' +], function (require, exports, module) { + 'use strict'; + var canLog = require('can-log'); + module.exports = { + warnTimeout: 5000, + logLevel: 0, + stringify: function (value) { + var flagUndefined = function flagUndefined(key, value) { + return value === undefined ? '/* void(undefined) */' : value; + }; + return JSON.stringify(value, flagUndefined, ' ').replace(/"\/\* void\(undefined\) \*\/"/g, 'undefined'); + }, + warn: function () { + }, + log: function () { + }, + error: function () { + }, + _logger: canLog._logger + }; +}); +/*can-util@3.11.1#js/dev/dev*/ +define('can-util/js/dev/dev', [ + 'require', + 'exports', + 'module', + 'can-log/dev/dev' +], function (require, exports, module) { + 'use strict'; + module.exports = require('can-log/dev/dev'); +}); +/*can-queues@1.0.0#queue-state*/ +define('can-queues/queue-state', function (require, exports, module) { + module.exports = { lastTask: null }; +}); +/*can-assign@1.1.1#can-assign*/ +define('can-assign', function (require, exports, module) { + module.exports = function (d, s) { + for (var prop in s) { + d[prop] = s[prop]; + } + return d; + }; +}); +/*can-queues@1.0.0#queue*/ +define('can-queues/queue', [ + 'require', + 'exports', + 'module', + 'can-queues/queue-state', + 'can-log/dev/dev', + 'can-assign' +], function (require, exports, module) { + var queueState = require('can-queues/queue-state'); + var canDev = require('can-log/dev/dev'); + var assign = require('can-assign'); + function noOperation() { + } + var Queue = function (name, callbacks) { + this.callbacks = assign({ + onFirstTask: noOperation, + onComplete: function () { + queueState.lastTask = null; + } + }, callbacks || {}); + this.name = name; + this.index = 0; + this.tasks = []; + this._log = false; + }; + Queue.prototype.constructor = Queue; + Queue.noop = noOperation; + Queue.prototype.enqueue = function (fn, context, args, meta) { + var len = this.tasks.push({ + fn: fn, + context: context, + args: args, + meta: meta || {} + }); + if (len === 1) { + this.callbacks.onFirstTask(this); + } + }; + Queue.prototype.flush = function () { + while (this.index < this.tasks.length) { + var task = this.tasks[this.index++]; + task.fn.apply(task.context, task.args); + } + this.index = 0; + this.tasks = []; + this.callbacks.onComplete(this); + }; + Queue.prototype.log = function () { + this._log = arguments.length ? arguments[0] : true; + }; + module.exports = Queue; +}); +/*can-queues@1.0.0#priority-queue*/ +define('can-queues/priority-queue', [ + 'require', + 'exports', + 'module', + 'can-queues/queue' +], function (require, exports, module) { + var Queue = require('can-queues/queue'); + var PriorityQueue = function () { + Queue.apply(this, arguments); + this.taskMap = new Map(); + this.taskContainersByPriority = []; + this.curPriorityIndex = Infinity; + this.curPriorityMax = 0; + this.isFlushing = false; + this.tasksRemaining = 0; + }; + PriorityQueue.prototype = Object.create(Queue.prototype); + PriorityQueue.prototype.constructor = PriorityQueue; + PriorityQueue.prototype.enqueue = function (fn, context, args, meta) { + if (!this.taskMap.has(fn)) { + this.tasksRemaining++; + var isFirst = this.taskContainersByPriority.length === 0; + var task = { + fn: fn, + context: context, + args: args, + meta: meta || {} + }; + var taskContainer = this.getTaskContainerAndUpdateRange(task); + taskContainer.tasks.push(task); + this.taskMap.set(fn, task); + if (isFirst) { + this.callbacks.onFirstTask(this); + } + } + }; + PriorityQueue.prototype.getTaskContainerAndUpdateRange = function (task) { + var priority = task.meta.priority || 0; + if (priority < this.curPriorityIndex) { + this.curPriorityIndex = priority; + } + if (priority > this.curPriorityMax) { + this.curPriorityMax = priority; + } + var tcByPriority = this.taskContainersByPriority; + var taskContainer = tcByPriority[priority]; + if (!taskContainer) { + taskContainer = tcByPriority[priority] = { + tasks: [], + index: 0 + }; + } + return taskContainer; + }; + PriorityQueue.prototype.flush = function () { + if (this.isFlushing) { + return; + } + this.isFlushing = true; + while (true) { + if (this.curPriorityIndex <= this.curPriorityMax) { + var taskContainer = this.taskContainersByPriority[this.curPriorityIndex]; + if (taskContainer && taskContainer.tasks.length > taskContainer.index) { + var task = taskContainer.tasks[taskContainer.index++]; + this.tasksRemaining--; + this.taskMap['delete'](task.fn); + task.fn.apply(task.context, task.args); + } else { + this.curPriorityIndex++; + } + } else { + this.taskMap = new Map(); + this.curPriorityIndex = Infinity; + this.curPriorityMax = 0; + this.taskContainersByPriority = []; + this.isFlushing = false; + this.callbacks.onComplete(this); + return; + } + } + }; + PriorityQueue.prototype.isEnqueued = function (fn) { + return this.taskMap.has(fn); + }; + PriorityQueue.prototype.flushQueuedTask = function (fn) { + var task = this.dequeue(fn); + if (task) { + task.fn.apply(task.context, task.args); + } + }; + PriorityQueue.prototype.dequeue = function (fn) { + var task = this.taskMap.get(fn); + if (task) { + var priority = task.meta.priority || 0; + var taskContainer = this.taskContainersByPriority[priority]; + var index = taskContainer.tasks.indexOf(task, taskContainer.index); + if (index >= 0) { + taskContainer.tasks.splice(index, 1); + this.tasksRemaining--; + this.taskMap['delete'](task.fn); + return task; + } else { + console.warn('Task', fn, 'has already run'); + } + } + }; + PriorityQueue.prototype.tasksRemainingCount = function () { + return this.tasksRemaining; + }; + module.exports = PriorityQueue; +}); +/*can-queues@1.0.0#completion-queue*/ +define('can-queues/completion-queue', [ + 'require', + 'exports', + 'module', + 'can-queues/queue' +], function (require, exports, module) { + var Queue = require('can-queues/queue'); + var CompletionQueue = function () { + Queue.apply(this, arguments); + this.flushCount = 0; + }; + CompletionQueue.prototype = Object.create(Queue.prototype); + CompletionQueue.prototype.constructor = CompletionQueue; + CompletionQueue.prototype.flush = function () { + if (this.flushCount === 0) { + this.flushCount++; + while (this.index < this.tasks.length) { + var task = this.tasks[this.index++]; + task.fn.apply(task.context, task.args); + } + this.index = 0; + this.tasks = []; + this.flushCount--; + this.callbacks.onComplete(this); + } + }; + module.exports = CompletionQueue; +}); +/*can-queues@1.0.0#can-queues*/ +define('can-queues', [ + 'require', + 'exports', + 'module', + 'can-util/js/dev/dev', + 'can-queues/queue', + 'can-queues/priority-queue', + 'can-queues/queue-state', + 'can-queues/completion-queue', + 'can-namespace' +], function (require, exports, module) { + var canDev = require('can-util/js/dev/dev'); + var Queue = require('can-queues/queue'); + var PriorityQueue = require('can-queues/priority-queue'); + var queueState = require('can-queues/queue-state'); + var CompletionQueue = require('can-queues/completion-queue'); + var ns = require('can-namespace'); + var batchStartCounter = 0; + var addedTask = false; + var isFlushing = false; + var batchNum = 0; + var batchData; + var queueNames = [ + 'notify', + 'derive', + 'domUI', + 'mutate' + ]; + var NOTIFY_QUEUE, DERIVE_QUEUE, DOM_UI_QUEUE, MUTATE_QUEUE; + NOTIFY_QUEUE = new Queue('NOTIFY', { + onComplete: function () { + DERIVE_QUEUE.flush(); + }, + onFirstTask: function () { + if (!batchStartCounter) { + NOTIFY_QUEUE.flush(); + } else { + addedTask = true; + } + } + }); + DERIVE_QUEUE = new PriorityQueue('DERIVE', { + onComplete: function () { + DOM_UI_QUEUE.flush(); + }, + onFirstTask: function () { + addedTask = true; + } + }); + DOM_UI_QUEUE = new CompletionQueue('DOM_UI', { + onComplete: function () { + MUTATE_QUEUE.flush(); + }, + onFirstTask: function () { + addedTask = true; + } + }); + MUTATE_QUEUE = new Queue('MUTATE', { + onComplete: function () { + queueState.lastTask = null; + isFlushing = false; + }, + onFirstTask: function () { + addedTask = true; + } + }); + var queues = { + Queue: Queue, + PriorityQueue: PriorityQueue, + CompletionQueue: CompletionQueue, + notifyQueue: NOTIFY_QUEUE, + deriveQueue: DERIVE_QUEUE, + domUIQueue: DOM_UI_QUEUE, + mutateQueue: MUTATE_QUEUE, + batch: { + start: function () { + batchStartCounter++; + if (batchStartCounter === 1) { + batchNum++; + batchData = { number: batchNum }; + } + }, + stop: function () { + batchStartCounter--; + if (batchStartCounter === 0) { + if (addedTask) { + addedTask = false; + isFlushing = true; + NOTIFY_QUEUE.flush(); + } + } + }, + isCollecting: function () { + return batchStartCounter > 0; + }, + number: function () { + return batchNum; + }, + data: function () { + return batchData; + } + }, + enqueueByQueue: function enqueueByQueue(fnByQueue, context, args, makeMeta, reasonLog) { + if (fnByQueue) { + queues.batch.start(); + queueNames.forEach(function (queueName) { + var name = queueName + 'Queue'; + var QUEUE = queues[name]; + var tasks = fnByQueue[queueName]; + if (tasks !== undefined) { + tasks.forEach(function (fn) { + var meta = makeMeta != null ? makeMeta(fn, context, args) : {}; + meta.reasonLog = reasonLog; + QUEUE.enqueue(fn, context, args, meta); + }); + } + }); + queues.batch.stop(); + } + }, + stack: function () { + var current = queueState.lastTask; + var stack = []; + while (current) { + stack.unshift(current); + current = current.meta.parentTask; + } + return stack; + }, + logStack: function () { + var stack = this.stack(); + stack.forEach(function (task, i) { + var meta = task.meta; + if (i === 0 && meta && meta.reasonLog) { + canDev.log.apply(canDev, meta.reasonLog); + } + var log = meta && meta.log ? meta.log : [ + task.fn.name, + task + ]; + canDev.log.apply(canDev, [task.meta.stack.name + ' ran task:'].concat(log)); + }); + }, + taskCount: function () { + console.warn('THIS IS NOT USED RIGHT?'); + return NOTIFY_QUEUE.tasks.length + DERIVE_QUEUE.tasks.length + DOM_UI_QUEUE.tasks.length + MUTATE_QUEUE.tasks.length; + }, + flush: function () { + NOTIFY_QUEUE.flush(); + }, + log: function () { + NOTIFY_QUEUE.log.apply(NOTIFY_QUEUE, arguments); + DERIVE_QUEUE.log.apply(DERIVE_QUEUE, arguments); + DOM_UI_QUEUE.log.apply(DOM_UI_QUEUE, arguments); + MUTATE_QUEUE.log.apply(MUTATE_QUEUE, arguments); + } + }; + if (ns.queues) { + throw new Error('You can\'t have two versions of can-queues, check your dependencies'); + } else { + module.exports = ns.queues = queues; + } +}); +/*can-key-tree@1.0.0#can-key-tree*/ +define('can-key-tree', [ + 'require', + 'exports', + 'module', + 'can-reflect' +], function (require, exports, module) { + var reflect = require('can-reflect'); + function isBuiltInPrototype(obj) { + if (obj === Object.prototype) { + return true; + } + var protoString = Object.prototype.toString.call(obj); + var isNotObjObj = protoString !== '[object Object]'; + var isObjSomething = protoString.indexOf('[object ') !== -1; + return isNotObjObj && isObjSomething; + } + function getDeepSize(root, level) { + if (level === 0) { + return reflect.size(root); + } else if (reflect.size(root) === 0) { + return 0; + } else { + var count = 0; + reflect.each(root, function (value) { + count += getDeepSize(value, level - 1); + }); + return count; + } + } + function getDeep(node, items, depth, maxDepth) { + if (!node) { + return; + } + if (maxDepth === depth) { + if (reflect.isMoreListLikeThanMapLike(node)) { + reflect.addValues(items, reflect.toArray(node)); + } else { + throw new Error('can-key-tree: Map-type leaf containers are not supported yet.'); + } + } else { + reflect.each(node, function (value) { + getDeep(value, items, depth + 1, maxDepth); + }); + } + } + function clearDeep(node, keys, maxDepth, deleteHandler) { + if (maxDepth === keys.length) { + if (reflect.isMoreListLikeThanMapLike(node)) { + var valuesToRemove = reflect.toArray(node); + if (deleteHandler) { + valuesToRemove.forEach(function (value) { + deleteHandler.apply(null, keys.concat(value)); + }); + } + reflect.removeValues(node, valuesToRemove); + } else { + throw new Error('can-key-tree: Map-type leaf containers are not supported yet.'); + } + } else { + reflect.each(node, function (value, key) { + clearDeep(value, keys.concat(key), maxDepth, deleteHandler); + reflect.deleteKeyValue(node, key); + }); + } + } + var KeyTree = function (treeStructure, callbacks) { + this.callbacks = callbacks || {}; + this.treeStructure = treeStructure; + var FirstConstructor = treeStructure[0]; + if (reflect.isConstructorLike(FirstConstructor)) { + this.root = new FirstConstructor(); + } else { + this.root = FirstConstructor; + } + }; + reflect.assign(KeyTree.prototype, { + add: function (keys) { + if (keys.length > this.treeStructure.length) { + throw new Error('can-key-tree: Can not add path deeper than tree.'); + } + var place = this.root; + var rootWasEmpty = reflect.size(this.root) === 0; + for (var i = 0; i < keys.length - 1; i++) { + var key = keys[i]; + var childNode = reflect.getKeyValue(place, key); + if (!childNode) { + var Constructor = this.treeStructure[i + 1]; + if (isBuiltInPrototype(Constructor.prototype)) { + childNode = new Constructor(); + } else { + childNode = new Constructor(key); + } + reflect.setKeyValue(place, key, childNode); + } + place = childNode; + } + if (reflect.isMoreListLikeThanMapLike(place)) { + reflect.addValues(place, [keys[keys.length - 1]]); + } else { + throw new Error('can-key-tree: Map types are not supported yet.'); + } + if (rootWasEmpty && this.callbacks.onFirst) { + this.callbacks.onFirst.call(this); + } + return this; + }, + getNode: function (keys) { + var node = this.root; + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + node = reflect.getKeyValue(node, key); + if (!node) { + return; + } + } + return node; + }, + get: function (keys) { + var node = this.getNode(keys); + if (this.treeStructure.length === keys.length) { + return node; + } else { + var Type = this.treeStructure[this.treeStructure.length - 1]; + var items = new Type(); + getDeep(node, items, keys.length, this.treeStructure.length - 1); + return items; + } + }, + delete: function (keys, deleteHandler) { + var parentNode = this.root, path = [this.root], lastKey = keys[keys.length - 1]; + for (var i = 0; i < keys.length - 1; i++) { + var key = keys[i]; + var childNode = reflect.getKeyValue(parentNode, key); + if (childNode === undefined) { + return false; + } else { + path.push(childNode); + } + parentNode = childNode; + } + if (!keys.length) { + clearDeep(parentNode, [], this.treeStructure.length - 1, deleteHandler); + } else if (keys.length === this.treeStructure.length) { + if (reflect.isMoreListLikeThanMapLike(parentNode)) { + if (deleteHandler) { + deleteHandler.apply(null, keys.concat(lastKey)); + } + reflect.removeValues(parentNode, [lastKey]); + } else { + throw new Error('can-key-tree: Map types are not supported yet.'); + } + } else { + var nodeToRemove = reflect.getKeyValue(parentNode, lastKey); + if (nodeToRemove !== undefined) { + clearDeep(nodeToRemove, keys, this.treeStructure.length - 1, deleteHandler); + reflect.deleteKeyValue(parentNode, lastKey); + } else { + return false; + } + } + for (i = path.length - 2; i >= 0; i--) { + if (reflect.size(parentNode) === 0) { + parentNode = path[i]; + reflect.deleteKeyValue(parentNode, keys[i]); + } else { + break; + } + } + if (this.callbacks.onEmpty && reflect.size(this.root) === 0) { + this.callbacks.onEmpty.call(this); + } + return true; + }, + size: function () { + return getDeepSize(this.root, this.treeStructure.length - 1); + } + }); + module.exports = KeyTree; +}); +/*can-globals@1.0.0#can-globals-proto*/ +define('can-globals/can-globals-proto', [ + 'require', + 'exports', + 'module', + 'can-reflect' +], function (require, exports, module) { + (function (global, require, exports, module) { + 'use strict'; + var canReflect = require('can-reflect'); + function dispatch(key) { + var handlers = this.eventHandlers[key]; + if (handlers) { + var handlersCopy = handlers.slice(); + var value = this.getKeyValue(key); + for (var i = 0; i < handlersCopy.length; i++) { + handlersCopy[i](value); + } + } + } + function Globals() { + this.eventHandlers = {}; + this.properties = {}; + } + Globals.prototype.define = function (key, value, enableCache) { + if (enableCache === undefined) { + enableCache = true; + } + if (!this.properties[key]) { + this.properties[key] = { + default: value, + value: value, + enableCache: enableCache + }; + } + return this; + }; + Globals.prototype.getKeyValue = function (key) { + var property = this.properties[key]; + if (property) { + if (typeof property.value === 'function') { + if (property.cachedValue) { + return property.cachedValue; + } + if (property.enableCache) { + property.cachedValue = property.value(); + return property.cachedValue; + } else { + return property.value(); + } + } + return property.value; + } + }; + Globals.prototype.makeExport = function (key) { + return function (value) { + if (arguments.length === 0) { + return this.getKeyValue(key); + } + if (typeof value === 'undefined' || value === null) { + this.deleteKeyValue(key); + } else { + if (typeof value === 'function') { + this.setKeyValue(key, function () { + return value; + }); + } else { + this.setKeyValue(key, value); + } + return value; + } + }.bind(this); + }; + Globals.prototype.offKeyValue = function (key, handler) { + if (this.properties[key]) { + var handlers = this.eventHandlers[key]; + if (handlers) { + var i = handlers.indexOf(handler); + handlers.splice(i, 1); + } + } + return this; + }; + Globals.prototype.onKeyValue = function (key, handler) { + if (this.properties[key]) { + if (!this.eventHandlers[key]) { + this.eventHandlers[key] = []; + } + this.eventHandlers[key].push(handler); + } + return this; + }; + Globals.prototype.deleteKeyValue = function (key) { + var property = this.properties[key]; + if (property !== undefined) { + property.value = property.default; + property.cachedValue = undefined; + dispatch.call(this, key); + } + return this; + }; + Globals.prototype.setKeyValue = function (key, value) { + if (!this.properties[key]) { + return this.define(key, value); + } + var property = this.properties[key]; + property.value = value; + property.cachedValue = undefined; + dispatch.call(this, key); + return this; + }; + Globals.prototype.reset = function () { + for (var key in this.properties) { + if (this.properties.hasOwnProperty(key)) { + this.properties[key].value = this.properties[key].default; + this.properties[key].cachedValue = undefined; + dispatch.call(this, key); + } + } + return this; + }; + canReflect.assignSymbols(Globals.prototype, { + 'can.getKeyValue': Globals.prototype.getKeyValue, + 'can.setKeyValue': Globals.prototype.setKeyValue, + 'can.deleteKeyValue': Globals.prototype.deleteKeyValue, + 'can.onKeyValue': Globals.prototype.onKeyValue, + 'can.offKeyValue': Globals.prototype.offKeyValue + }); + module.exports = Globals; + }(function () { + return this; + }(), require, exports, module)); +}); +/*can-globals@1.0.0#can-globals-instance*/ +define('can-globals/can-globals-instance', [ + 'require', + 'exports', + 'module', + 'can-namespace', + 'can-globals/can-globals-proto' +], function (require, exports, module) { + (function (global, require, exports, module) { + 'use strict'; + var namespace = require('can-namespace'); + var Globals = require('can-globals/can-globals-proto'); + var globals = new Globals(); + if (namespace.globals) { + throw new Error('You can\'t have two versions of can-globals, check your dependencies'); + } else { + module.exports = namespace.globals = globals; + } + }(function () { + return this; + }(), require, exports, module)); +}); +/*can-globals@1.0.0#global/global*/ +define('can-globals/global/global', [ + 'require', + 'exports', + 'module', + 'can-globals/can-globals-instance' +], function (require, exports, module) { + (function (global, require, exports, module) { + 'use strict'; + var globals = require('can-globals/can-globals-instance'); + globals.define('global', function () { + return typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope ? self : typeof process === 'object' && {}.toString.call(process) === '[object process]' ? global : window; + }); + module.exports = globals.makeExport('global'); + }(function () { + return this; + }(), require, exports, module)); +}); +/*can-globals@1.0.0#document/document*/ +define('can-globals/document/document', [ + 'require', + 'exports', + 'module', + 'can-globals/global/global', + 'can-globals/can-globals-instance' +], function (require, exports, module) { + (function (global, require, exports, module) { + 'use strict'; + require('can-globals/global/global'); + var globals = require('can-globals/can-globals-instance'); + globals.define('document', function () { + return globals.getKeyValue('global').document; + }); + module.exports = globals.makeExport('document'); + }(function () { + return this; + }(), require, exports, module)); +}); +/*can-globals@1.0.0#is-node/is-node*/ +define('can-globals/is-node/is-node', [ + 'require', + 'exports', + 'module', + 'can-globals/can-globals-instance' +], function (require, exports, module) { + (function (global, require, exports, module) { + 'use strict'; + var globals = require('can-globals/can-globals-instance'); + globals.define('isNode', function () { + return typeof process === 'object' && {}.toString.call(process) === '[object process]'; + }); + module.exports = globals.makeExport('isNode'); + }(function () { + return this; + }(), require, exports, module)); +}); +/*can-globals@1.0.0#is-browser-window/is-browser-window*/ +define('can-globals/is-browser-window/is-browser-window', [ + 'require', + 'exports', + 'module', + 'can-globals/can-globals-instance', + 'can-globals/is-node/is-node' +], function (require, exports, module) { + (function (global, require, exports, module) { + 'use strict'; + var globals = require('can-globals/can-globals-instance'); + require('can-globals/is-node/is-node'); + globals.define('isBrowserWindow', function () { + var isNode = globals.getKeyValue('isNode'); + return typeof window !== 'undefined' && typeof document !== 'undefined' && isNode === false; + }); + module.exports = globals.makeExport('isBrowserWindow'); + }(function () { + return this; + }(), require, exports, module)); +}); +/*can-dom-events@1.1.1#helpers/util*/ +define('can-dom-events/helpers/util', [ + 'require', + 'exports', + 'module', + 'can-globals/document/document', + 'can-globals/is-browser-window/is-browser-window' +], function (require, exports, module) { + (function (global, require, exports, module) { + 'use strict'; + var getCurrentDocument = require('can-globals/document/document'); + var isBrowserWindow = require('can-globals/is-browser-window/is-browser-window'); + function getTargetDocument(target) { + return target.ownerDocument || getCurrentDocument(); + } + function createEvent(target, eventData, bubbles, cancelable) { + var doc = getTargetDocument(target); + var event = doc.createEvent('HTMLEvents'); + var eventType; + if (typeof eventData === 'string') { + eventType = eventData; + } else { + eventType = eventData.type; + for (var prop in eventData) { + if (event[prop] === undefined) { + event[prop] = eventData[prop]; + } + } + } + if (bubbles === undefined) { + bubbles = true; + } + event.initEvent(eventType, bubbles, cancelable); + return event; + } + function isDomEventTarget(obj) { + if (!(obj && obj.nodeName)) { + return obj === window; + } + var nodeType = obj.nodeType; + return nodeType === 1 || nodeType === 9 || nodeType === 11; + } + function addDomContext(context, args) { + if (isDomEventTarget(context)) { + args = Array.prototype.slice.call(args, 0); + args.unshift(context); + } + return args; + } + function removeDomContext(context, args) { + if (!isDomEventTarget(context)) { + args = Array.prototype.slice.call(args, 0); + context = args.shift(); + } + return { + context: context, + args: args + }; + } + var fixSyntheticEventsOnDisabled = false; + (function () { + if (!isBrowserWindow()) { + return; + } + var testEventName = 'fix_synthetic_events_on_disabled_test'; + var input = document.createElement('input'); + input.disabled = true; + var timer = setTimeout(function () { + fixSyntheticEventsOnDisabled = true; + }, 50); + var onTest = function onTest() { + clearTimeout(timer); + input.removeEventListener(testEventName, onTest); + }; + input.addEventListener(testEventName, onTest); + try { + var event = document.create('HTMLEvents'); + event.initEvent(testEventName, false); + input.dispatchEvent(event); + } catch (e) { + onTest(); + fixSyntheticEventsOnDisabled = true; + } + }()); + function isDispatchingOnDisabled(element, event) { + var eventType = event.type; + var isInsertedOrRemoved = eventType === 'inserted' || eventType === 'removed'; + var isDisabled = !!element.disabled; + return isInsertedOrRemoved && isDisabled; + } + function forceEnabledForDispatch(element, event) { + return fixSyntheticEventsOnDisabled && isDispatchingOnDisabled(element, event); + } + module.exports = { + createEvent: createEvent, + addDomContext: addDomContext, + removeDomContext: removeDomContext, + isDomEventTarget: isDomEventTarget, + getTargetDocument: getTargetDocument, + forceEnabledForDispatch: forceEnabledForDispatch + }; + }(function () { + return this; + }(), require, exports, module)); +}); +/*can-dom-events@1.1.1#helpers/make-event-registry*/ +define('can-dom-events/helpers/make-event-registry', function (require, exports, module) { + 'use strict'; + function EventRegistry() { + this._registry = {}; + } + module.exports = function makeEventRegistry() { + return new EventRegistry(); + }; + EventRegistry.prototype.has = function (eventType) { + return !!this._registry[eventType]; + }; + EventRegistry.prototype.get = function (eventType) { + return this._registry[eventType]; + }; + EventRegistry.prototype.add = function (event, eventType) { + if (!event) { + throw new Error('An EventDefinition must be provided'); + } + if (typeof event.addEventListener !== 'function') { + throw new TypeError('EventDefinition addEventListener must be a function'); + } + if (typeof event.removeEventListener !== 'function') { + throw new TypeError('EventDefinition removeEventListener must be a function'); + } + eventType = eventType || event.defaultEventType; + if (typeof eventType !== 'string') { + throw new TypeError('Event type must be a string, not ' + eventType); + } + if (this.has(eventType)) { + throw new Error('Event "' + eventType + '" is already registered'); + } + this._registry[eventType] = event; + var self = this; + return function remove() { + self._registry[eventType] = undefined; + }; + }; +}); +/*can-dom-events@1.1.1#helpers/-make-delegate-event-tree*/ +define('can-dom-events/helpers/-make-delegate-event-tree', [ + 'require', + 'exports', + 'module', + 'can-key-tree', + 'can-reflect' +], function (require, exports, module) { + var KeyTree = require('can-key-tree'); + var canReflect = require('can-reflect'); + var useCapture = function (eventType) { + return eventType === 'focus' || eventType === 'blur'; + }; + function makeDelegator(domEvents) { + var Delegator = function Delegator(parentKey) { + this.element = parentKey; + this.events = {}; + this.delegated = {}; + }; + canReflect.assignSymbols(Delegator.prototype, { + 'can.setKeyValue': function (eventType, handlersBySelector) { + var handler = this.delegated[eventType] = function (ev) { + canReflect.each(handlersBySelector, function (handlers, selector) { + var cur = ev.target; + do { + if (cur.matches(selector)) { + handlers.forEach(function (handler) { + handler.call(cur, ev); + }); + } + cur = cur.parentNode; + } while (cur && cur !== ev.currentTarget); + }); + }; + this.events[eventType] = handlersBySelector; + domEvents.addEventListener(this.element, eventType, handler, useCapture(eventType)); + }, + 'can.getKeyValue': function (eventType) { + return this.events[eventType]; + }, + 'can.deleteKeyValue': function (eventType) { + domEvents.removeEventListener(this.element, eventType, this.delegated[eventType], useCapture(eventType)); + delete this.delegated[eventType]; + delete this.events[eventType]; + }, + 'can.getOwnEnumerableKeys': function () { + return Object.keys(this.events); + } + }); + return Delegator; + } + module.exports = function makeDelegateEventTree(domEvents) { + var Delegator = makeDelegator(domEvents); + return new KeyTree([ + Map, + Delegator, + Object, + Array + ]); + }; +}); +/*can-dom-events@1.1.1#can-dom-events*/ +define('can-dom-events', [ + 'require', + 'exports', + 'module', + 'can-namespace', + 'can-dom-events/helpers/util', + 'can-dom-events/helpers/make-event-registry', + 'can-dom-events/helpers/-make-delegate-event-tree' +], function (require, exports, module) { + (function (global, require, exports, module) { + 'use strict'; + var namespace = require('can-namespace'); + var util = require('can-dom-events/helpers/util'); + var makeEventRegistry = require('can-dom-events/helpers/make-event-registry'); + var makeDelegateEventTree = require('can-dom-events/helpers/-make-delegate-event-tree'); + var domEvents = { + _eventRegistry: makeEventRegistry(), + addEvent: function (event, eventType) { + return this._eventRegistry.add(event, eventType); + }, + addEventListener: function (target, eventType) { + var hasCustomEvent = domEvents._eventRegistry.has(eventType); + if (hasCustomEvent) { + var event = domEvents._eventRegistry.get(eventType); + return event.addEventListener.apply(domEvents, arguments); + } + var eventArgs = Array.prototype.slice.call(arguments, 1); + return target.addEventListener.apply(target, eventArgs); + }, + removeEventListener: function (target, eventType) { + var hasCustomEvent = domEvents._eventRegistry.has(eventType); + if (hasCustomEvent) { + var event = domEvents._eventRegistry.get(eventType); + return event.removeEventListener.apply(domEvents, arguments); + } + var eventArgs = Array.prototype.slice.call(arguments, 1); + return target.removeEventListener.apply(target, eventArgs); + }, + addDelegateListener: function (target, eventType, selector, handler) { + domEvents._eventTree.add([ + target, + eventType, + selector, + handler + ]); + }, + removeDelegateListener: function (target, eventType, selector, handler) { + domEvents._eventTree.delete([ + target, + eventType, + selector, + handler + ]); + }, + dispatch: function (target, eventData, bubbles, cancelable) { + var event = util.createEvent(target, eventData, bubbles, cancelable); + var enableForDispatch = util.forceEnabledForDispatch(target, event); + if (enableForDispatch) { + target.disabled = false; + } + var ret = target.dispatchEvent(event); + if (enableForDispatch) { + target.disabled = true; + } + return ret; + } + }; + domEvents._eventTree = makeDelegateEventTree(domEvents); + module.exports = namespace.domEvents = domEvents; + }(function () { + return this; + }(), require, exports, module)); +}); +/*can-event-queue@1.0.0#dependency-record/merge*/ +define('can-event-queue/dependency-record/merge', [ + 'require', + 'exports', + 'module', + 'can-reflect' +], function (require, exports, module) { + var canReflect = require('can-reflect'); + var mergeValueDependencies = function mergeValueDependencies(obj, source) { + var sourceValueDeps = source.valueDependencies; + if (sourceValueDeps) { + var destValueDeps = obj.valueDependencies; + if (!destValueDeps) { + destValueDeps = new Set(); + obj.valueDependencies = destValueDeps; + } + canReflect.eachIndex(sourceValueDeps, function (dep) { + destValueDeps.add(dep); + }); + } + }; + var mergeKeyDependencies = function mergeKeyDependencies(obj, source) { + var sourcekeyDeps = source.keyDependencies; + if (sourcekeyDeps) { + var destKeyDeps = obj.keyDependencies; + if (!destKeyDeps) { + destKeyDeps = new Map(); + obj.keyDependencies = destKeyDeps; + } + canReflect.eachKey(sourcekeyDeps, function (keys, obj) { + var entry = destKeyDeps.get(obj); + if (!entry) { + entry = new Set(); + destKeyDeps.set(obj, entry); + } + canReflect.eachIndex(keys, function (key) { + entry.add(key); + }); + }); + } + }; + module.exports = function mergeDependencyRecords(object, source) { + mergeKeyDependencies(object, source); + mergeValueDependencies(object, source); + return object; + }; +}); +/*can-event-queue@1.0.0#map/map*/ +define('can-event-queue/map/map', [ + 'require', + 'exports', + 'module', + 'can-log/dev/dev', + 'can-queues', + 'can-reflect', + 'can-symbol', + 'can-key-tree', + 'can-dom-events', + 'can-dom-events/helpers/util', + 'can-event-queue/dependency-record/merge' +], function (require, exports, module) { + var canDev = require('can-log/dev/dev'); + var queues = require('can-queues'); + var canReflect = require('can-reflect'); + var canSymbol = require('can-symbol'); + var KeyTree = require('can-key-tree'); + var domEvents = require('can-dom-events'); + var isDomEventTarget = require('can-dom-events/helpers/util').isDomEventTarget; + var mergeDependencyRecords = require('can-event-queue/dependency-record/merge'); + var metaSymbol = canSymbol.for('can.meta'), dispatchBoundChangeSymbol = canSymbol.for('can.dispatchInstanceBoundChange'), dispatchInstanceOnPatchesSymbol = canSymbol.for('can.dispatchInstanceOnPatches'), onKeyValueSymbol = canSymbol.for('can.onKeyValue'), offKeyValueSymbol = canSymbol.for('can.offKeyValue'), onEventSymbol = canSymbol.for('can.onEvent'), offEventSymbol = canSymbol.for('can.offEvent'), onValueSymbol = canSymbol.for('can.onValue'), offValueSymbol = canSymbol.for('can.offValue'); + var legacyMapBindings; + function addHandlers(obj, meta) { + if (!meta.handlers) { + meta.handlers = new KeyTree([ + Object, + Object, + Object, + Array + ], { + onFirst: function () { + if (obj._eventSetup !== undefined) { + obj._eventSetup(); + } + if (obj.constructor[dispatchBoundChangeSymbol]) { + obj.constructor[dispatchBoundChangeSymbol](obj, true); + } + }, + onEmpty: function () { + if (obj._eventTeardown !== undefined) { + obj._eventTeardown(); + } + if (obj.constructor[dispatchBoundChangeSymbol]) { + obj.constructor[dispatchBoundChangeSymbol](obj, false); + } + } + }); + } + if (!meta.listenHandlers) { + meta.listenHandlers = new KeyTree([ + Map, + Map, + Object, + Array + ]); + } + } + var ensureMeta = function ensureMeta(obj) { + var meta = obj[metaSymbol]; + if (!meta) { + meta = {}; + canReflect.setKeyValue(obj, metaSymbol, meta); + } + addHandlers(obj, meta); + return meta; + }; + function stopListeningArgumentsToKeys(bindTarget, event, handler, queueName) { + if (arguments.length && canReflect.isPrimitive(bindTarget)) { + queueName = handler; + handler = event; + event = bindTarget; + bindTarget = this.context; + } + if (typeof event === 'function') { + queueName = handler; + handler = event; + event = undefined; + } + if (typeof handler === 'string') { + queueName = handler; + handler = undefined; + } + var keys = []; + if (bindTarget) { + keys.push(bindTarget); + if (event || handler || queueName) { + keys.push(event); + if (queueName || handler) { + keys.push(queueName || this.defaultQueue); + if (handler) { + keys.push(handler); + } + } + } + } + return keys; + } + var props = { + dispatch: function (event, args) { + if (!this.__inSetup) { + if (typeof event === 'string') { + event = { type: event }; + } + var meta = ensureMeta(this); + var handlers = meta.handlers; + var handlersByType = event.type !== undefined && handlers.getNode([event.type]); + var dispatchConstructorPatches = event.patches && this.constructor[dispatchInstanceOnPatchesSymbol]; + var patchesNode = event.patches !== undefined && handlers.getNode([ + 'can.patches', + 'onKeyValue' + ]); + var keysNode = event.keyChanged !== undefined && handlers.getNode([ + 'can.keys', + 'onKeyValue' + ]); + var batch = dispatchConstructorPatches || handlersByType || patchesNode || keysNode; + if (batch) { + queues.batch.start(); + } + if (handlersByType) { + if (handlersByType.onKeyValue) { + queues.enqueueByQueue(handlersByType.onKeyValue, this, args, event.makeMeta, event.reasonLog); + } + if (handlersByType.event) { + event.batchNum = queues.batch.number(); + var eventAndArgs = [event].concat(args); + queues.enqueueByQueue(handlersByType.event, this, eventAndArgs, event.makeMeta, event.reasonLog); + } + } + if (keysNode) { + queues.enqueueByQueue(keysNode, this, [event.keyChanged], event.makeMeta, event.reasonLog); + } + if (patchesNode) { + queues.enqueueByQueue(patchesNode, this, [event.patches], event.makeMeta, event.reasonLog); + } + if (dispatchConstructorPatches) { + this.constructor[dispatchInstanceOnPatchesSymbol](this, event.patches); + } + if (batch) { + queues.batch.stop(); + } + } + return event; + }, + addEventListener: function (key, handler, queueName) { + ensureMeta(this).handlers.add([ + key, + 'event', + queueName || 'mutate', + handler + ]); + return this; + }, + removeEventListener: function (key, handler, queueName) { + if (key === undefined) { + var handlers = ensureMeta(this).handlers; + var keyHandlers = handlers.getNode([]); + Object.keys(keyHandlers).forEach(function (key) { + handlers.delete([ + key, + 'event' + ]); + }); + } else if (!handler && !queueName) { + ensureMeta(this).handlers.delete([ + key, + 'event' + ]); + } else if (!handler) { + ensureMeta(this).handlers.delete([ + key, + 'event', + queueName || 'mutate' + ]); + } else { + ensureMeta(this).handlers.delete([ + key, + 'event', + queueName || 'mutate', + handler + ]); + } + return this; + }, + one: function (event, handler) { + var one = function () { + legacyMapBindings.off.call(this, event, one); + return handler.apply(this, arguments); + }; + legacyMapBindings.on.call(this, event, one); + return this; + }, + listenTo: function (bindTarget, event, handler, queueName) { + if (canReflect.isPrimitive(bindTarget)) { + queueName = handler; + handler = event; + event = bindTarget; + bindTarget = this; + } + if (typeof event === 'function') { + queueName = handler; + handler = event; + event = undefined; + } + ensureMeta(this).listenHandlers.add([ + bindTarget, + event, + queueName || 'mutate', + handler + ]); + legacyMapBindings.on.call(bindTarget, event, handler, queueName || 'mutate'); + return this; + }, + stopListening: function () { + var keys = stopListeningArgumentsToKeys.apply({ + context: this, + defaultQueue: 'mutate' + }, arguments); + var listenHandlers = ensureMeta(this).listenHandlers; + function deleteHandler(bindTarget, event, queue, handler) { + legacyMapBindings.off.call(bindTarget, event, handler, queue); + } + listenHandlers.delete(keys, deleteHandler); + return this; + }, + on: function (eventName, handler, queue) { + var listenWithDOM = isDomEventTarget(this); + if (listenWithDOM) { + if (typeof handler === 'string') { + domEvents.addDelegateListener(this, eventName, handler, queue); + } else { + domEvents.addEventListener(this, eventName, handler, queue); + } + } else { + if ('addEventListener' in this) { + this.addEventListener(eventName, handler, queue); + } else if (this[onKeyValueSymbol]) { + canReflect.onKeyValue(this, eventName, handler, queue); + } else if (this[onEventSymbol]) { + this[onEventSymbol](eventName, handler, queue); + } else { + if (!eventName && this[onValueSymbol]) { + canReflect.onValue(this, handler, queue); + } else { + throw new Error('can-event-queue: Unable to bind ' + eventName); + } + } + } + return this; + }, + off: function (eventName, handler, queue) { + var listenWithDOM = isDomEventTarget(this); + if (listenWithDOM) { + if (typeof handler === 'string') { + domEvents.removeDelegateListener(this, eventName, handler, queue); + } else { + domEvents.removeEventListener(this, eventName, handler, queue); + } + } else { + if ('removeEventListener' in this) { + this.removeEventListener(eventName, handler, queue); + } else if (this[offKeyValueSymbol]) { + canReflect.offKeyValue(this, eventName, handler, queue); + } else if (this[offEventSymbol]) { + this[offEventSymbol](eventName, handler, queue); + } else { + if (!eventName && this[offValueSymbol]) { + canReflect.offValue(this, handler, queue); + } else { + throw new Error('can-event-queue: Unable to unbind ' + eventName); + } + } + } + return this; + } + }; + var symbols = { + 'can.onKeyValue': function (key, handler, queueName) { + ensureMeta(this).handlers.add([ + key, + 'onKeyValue', + queueName || 'mutate', + handler + ]); + }, + 'can.offKeyValue': function (key, handler, queueName) { + ensureMeta(this).handlers.delete([ + key, + 'onKeyValue', + queueName || 'mutate', + handler + ]); + }, + 'can.isBound': function () { + return ensureMeta(this).handlers.size() > 0; + }, + 'can.getWhatIChange': function getWhatIChange(key) { + }, + 'can.onPatches': function (handler, queue) { + var handlers = ensureMeta(this).handlers; + handlers.add([ + 'can.patches', + 'onKeyValue', + queue || 'notify', + handler + ]); + }, + 'can.offPatches': function (handler, queue) { + var handlers = ensureMeta(this).handlers; + handlers.delete([ + 'can.patches', + 'onKeyValue', + queue || 'notify', + handler + ]); + } + }; + function defineNonEnumerable(obj, prop, value) { + Object.defineProperty(obj, prop, { + enumerable: false, + value: value + }); + } + legacyMapBindings = function (obj) { + canReflect.assignMap(obj, props); + return canReflect.assignSymbols(obj, symbols); + }; + defineNonEnumerable(legacyMapBindings, 'addHandlers', addHandlers); + defineNonEnumerable(legacyMapBindings, 'stopListeningArgumentsToKeys', stopListeningArgumentsToKeys); + props.bind = props.addEventListener; + props.unbind = props.removeEventListener; + canReflect.assignMap(legacyMapBindings, props); + canReflect.assignSymbols(legacyMapBindings, symbols); + defineNonEnumerable(legacyMapBindings, 'start', function () { + console.warn('use can-queues.batch.start()'); + queues.batch.start(); + }); + defineNonEnumerable(legacyMapBindings, 'stop', function () { + console.warn('use can-queues.batch.stop()'); + queues.batch.stop(); + }); + defineNonEnumerable(legacyMapBindings, 'flush', function () { + console.warn('use can-queues.flush()'); + queues.flush(); + }); + defineNonEnumerable(legacyMapBindings, 'afterPreviousEvents', function (handler) { + console.warn('don\'t use afterPreviousEvents'); + queues.mutateQueue.enqueue(function afterPreviousEvents() { + queues.mutateQueue.enqueue(handler); + }); + queues.flush(); + }); + defineNonEnumerable(legacyMapBindings, 'after', function (handler) { + console.warn('don\'t use after'); + queues.mutateQueue.enqueue(handler); + queues.flush(); + }); + module.exports = legacyMapBindings; +}); +/*can-observe@2.0.0-pre.22#src/-symbols*/ +define('can-observe/src/-symbols', [ + 'require', + 'exports', + 'module', + 'can-symbol' +], function (require, exports, module) { + var canSymbol = require('can-symbol'); + module.exports = { + metaSymbol: canSymbol.for('can.meta'), + patchesSymbol: 'can.patches', + keysSymbol: 'can.keys' + }; +}); +/*can-observe@2.0.0-pre.22#src/-observable-store*/ +define('can-observe/src/-observable-store', function (require, exports, module) { + module.exports = { + proxiedObjects: new WeakMap(), + proxies: new WeakSet() + }; +}); +/*can-observe@2.0.0-pre.22#src/-helpers*/ +define('can-observe/src/-helpers', [ + 'require', + 'exports', + 'module', + 'can-symbol' +], function (require, exports, module) { + var canSymbol = require('can-symbol'); + var metaSymbol = canSymbol.for('can.meta'); + var definitionsSymbol = canSymbol.for('can.typeDefinitions'); + var classTest = /^\s*class\s+/; + var helpers = { + assignEverything: function (d, s) { + Object.getOwnPropertyNames(s).concat(Object.getOwnPropertySymbols(s)).forEach(function (key) { + Object.defineProperty(d, key, Object.getOwnPropertyDescriptor(s, key)); + }); + return d; + }, + isBuiltInButNotArrayOrPlainObject: function (obj) { + if (Array.isArray(obj)) { + return false; + } + if (typeof obj === 'function') { + var fnCode = obj.toString(); + if (fnCode.indexOf('[native code]') > 0) { + return true; + } else { + return false; + } + } else { + var toString = Object.prototype.toString.call(obj); + return toString !== '[object Object]' && toString.indexOf('[object ') !== -1; + } + }, + inheritsFromArray: function (obj) { + var cur = obj; + do { + if (Array.isArray(cur)) { + return true; + } + cur = Object.getPrototypeOf(cur); + } while (cur); + return false; + }, + isClass: function (obj) { + return typeof obj === 'function' && classTest.test(obj.toString()); + }, + supportsClass: function () { + try { + eval('"use strict"; class A{};'); + return true; + } catch (e) { + return false; + } + }(), + makeSimpleExtender: function (BaseType) { + return function etend(name, staticProps, prototypeProps) { + var Type = function () { + var source = this; + var instance = BaseType.apply(this, arguments); + if (source.init) { + instance[metaSymbol].preventSideEffects++; + source.init.apply(instance, arguments); + instance[metaSymbol].preventSideEffects--; + } + return instance; + }; + helpers.assignEverything(Type, BaseType); + helpers.assignEverything(Type, staticProps || {}); + Type.prototype = Object.create(BaseType.prototype); + helpers.assignEverything(Type.prototype, prototypeProps || {}); + Type.prototype.constructor = Type; + Type.prototype[definitionsSymbol] = Object.create(BaseType.prototype[definitionsSymbol] || null); + return Type; + }; + } + }; + module.exports = helpers; +}); +/*can-observe@2.0.0-pre.22#src/-add-get-key-dependencies*/ +define('can-observe/src/-add-get-key-dependencies', [ + 'require', + 'exports', + 'module', + 'can-symbol' +], function (require, exports, module) { + var canSymbol = require('can-symbol'); + var getKeyDependenciesSymbol = canSymbol.for('can.getKeyDependencies'); + var computedDefinitionsSymbol = canSymbol.for('can.computedDefinitions'); + module.exports = function addGetterKeyDependencies(obj) { + obj[getKeyDependenciesSymbol] = function getKeyDependencies(key) { + var computed = this[computedDefinitionsSymbol]; + if (computed) { + var getObservation = computed[key]; + var observationData = getObservation && getObservation(this); + if (observationData != null) { + return { valueDependencies: new Set([observationData.observation]) }; + } + } + }; + return obj; + }; +}); +/*can-observe@2.0.0-pre.22#src/-make-object*/ +define('can-observe/src/-make-object', [ + 'require', + 'exports', + 'module', + 'can-reflect', + 'can-observation-recorder', + 'can-event-queue/map/map', + 'can-observe/src/-symbols', + 'can-observe/src/-observable-store', + 'can-observe/src/-helpers', + 'can-observe/src/-add-get-key-dependencies' +], function (require, exports, module) { + var canReflect = require('can-reflect'); + var ObservationRecorder = require('can-observation-recorder'); + var mapBindings = require('can-event-queue/map/map'); + var symbols = require('can-observe/src/-symbols'); + var observableStore = require('can-observe/src/-observable-store'); + var helpers = require('can-observe/src/-helpers'); + var addGetterKeyDependencies = require('can-observe/src/-add-get-key-dependencies'); + var hasOwn = Object.prototype.hasOwnProperty; + var isSymbolLike = canReflect.isSymbolLike; + var proxyKeys = Object.create(null); + Object.getOwnPropertySymbols(mapBindings).forEach(function (symbol) { + proxyKeys[symbol] = mapBindings[symbol]; + }); + addGetterKeyDependencies(proxyKeys); + var makeObject = { + observable: function (object, options) { + if (options.shouldRecordObservation === undefined) { + options.shouldRecordObservation = makeObject.shouldRecordObservationOnOwnAndMissingKeys; + } + var meta = { + target: object, + proxyKeys: options.proxyKeys !== undefined ? options.proxyKeys : Object.create(makeObject.proxyKeys()), + options: options, + preventSideEffects: 0 + }; + meta.proxyKeys[symbols.metaSymbol] = meta; + meta.proxy = new Proxy(object, { + get: makeObject.get.bind(meta), + set: makeObject.set.bind(meta), + ownKeys: makeObject.ownKeys.bind(meta), + deleteProperty: makeObject.deleteProperty.bind(meta), + meta: meta + }); + mapBindings.addHandlers(meta.proxy, meta); + return meta.proxy; + }, + proxyKeys: function () { + return proxyKeys; + }, + get: function (target, key, receiver) { + var proxyKey = this.proxyKeys[key]; + if (proxyKey !== undefined) { + return proxyKey; + } + if (isSymbolLike(key)) { + return target[key]; + } + var keyInfo = makeObject.getKeyInfo(target, key, receiver, this); + var value = keyInfo.targetValue; + if (!keyInfo.valueIsInvariant) { + value = makeObject.getValueFromStore(key, value, this); + } + if (this.options.shouldRecordObservation(keyInfo, this)) { + ObservationRecorder.add(this.proxy, key.toString()); + } + if (keyInfo.parentObservableGetCalledOn) { + ObservationRecorder.add(keyInfo.parentObservableGetCalledOn, key.toString()); + } + return value; + }, + set: function (target, key, value, receiver) { + if (receiver !== this.proxy) { + return makeObject.setKey(receiver, key, value, this); + } + value = makeObject.getValueToSet(key, value, this); + makeObject.setValueAndOnChange(key, value, this, function (key, value, meta, hadOwn, old) { + mapBindings.dispatch.call(meta.proxy, { + type: key, + patches: [{ + key: key, + type: hadOwn ? 'set' : 'add', + value: value + }], + keyChanged: !hadOwn ? key : undefined + }, [ + value, + old + ]); + }); + return true; + }, + deleteProperty: function (target, key) { + var old = this.target[key], deleteSuccessful = delete this.target[key]; + if (deleteSuccessful && this.preventSideEffects === 0 && old !== undefined) { + mapBindings.dispatch.call(this.proxy, { + type: key, + patches: [{ + key: key, + type: 'delete' + }], + keyChanged: key + }, [ + undefined, + old + ]); + } + return deleteSuccessful; + }, + ownKeys: function (target, key) { + ObservationRecorder.add(this.proxy, symbols.keysSymbol); + return Object.getOwnPropertyNames(this.target).concat(Object.getOwnPropertySymbols(this.target)).concat(Object.getOwnPropertySymbols(this.proxyKeys)); + }, + getKeyInfo: function (target, key, receiver, meta) { + var descriptor = Object.getOwnPropertyDescriptor(target, key); + var propertyInfo = { + key: key, + descriptor: descriptor, + targetHasOwnKey: Boolean(descriptor), + getCalledOnParent: receiver !== meta.proxy, + protoHasKey: false, + valueIsInvariant: false, + targetValue: undefined, + isAccessor: false + }; + if (propertyInfo.getCalledOnParent === true) { + propertyInfo.parentObservableGetCalledOn = observableStore.proxiedObjects.get(receiver); + } + if (descriptor !== undefined) { + propertyInfo.valueIsInvariant = descriptor.writable === false; + if (descriptor.get !== undefined) { + propertyInfo.targetValue = descriptor.get.call(propertyInfo.parentObservableGetCalledOn || receiver); + propertyInfo.isAccessor = true; + } else { + propertyInfo.targetValue = descriptor.value; + } + } else { + propertyInfo.targetValue = meta.target[key]; + propertyInfo.protoHasKey = propertyInfo.targetValue !== undefined ? true : key in target; + } + return propertyInfo; + }, + shouldRecordObservationOnOwnAndMissingKeys: function (keyInfo, meta) { + return meta.preventSideEffects === 0 && !keyInfo.isAccessor && (keyInfo.targetHasOwnKey || !keyInfo.protoHasKey && !Object.isSealed(meta.target)); + }, + setKey: function (receiver, key, value) { + Object.defineProperty(receiver, key, { + value: value, + configurable: true, + enumerable: true, + writable: true + }); + return true; + }, + getValueToSet: function (key, value, meta) { + if (!canReflect.isSymbolLike(key) && meta.handlers.getNode([key])) { + return makeObject.getValueFromStore(key, value, meta); + } + return value; + }, + getValueFromStore: function (key, value, meta) { + if (!canReflect.isPrimitive(value) && !canReflect.isObservableLike(value) && !observableStore.proxies.has(value)) { + if (observableStore.proxiedObjects.has(value)) { + value = observableStore.proxiedObjects.get(value); + } else if (!helpers.isBuiltInButNotArrayOrPlainObject(value)) { + value = meta.options.observe(value); + } + } + return value; + }, + setValueAndOnChange: function (key, value, data, onChange) { + var old, change; + var hadOwn = hasOwn.call(data.target, key); + var descriptor = Object.getOwnPropertyDescriptor(data.target, key); + if (descriptor && descriptor.set) { + descriptor.set.call(data.proxy, value); + } else { + old = data.target[key]; + change = old !== value; + if (change) { + data.target[key] = value; + if (data.preventSideEffects === 0) { + onChange(key, value, data, hadOwn, old); + } + } + } + } + }; + module.exports = makeObject; +}); +/*can-observe@2.0.0-pre.22#src/-make-array*/ +define('can-observe/src/-make-array', [ + 'require', + 'exports', + 'module', + 'can-observation-recorder', + 'can-event-queue/map/map', + 'can-reflect', + 'can-observe/src/-make-object', + 'can-observe/src/-symbols', + 'can-observe/src/-observable-store', + 'can-observe/src/-helpers' +], function (require, exports, module) { + var ObservationRecorder = require('can-observation-recorder'); + var mapBindings = require('can-event-queue/map/map'); + var canReflect = require('can-reflect'); + var makeObject = require('can-observe/src/-make-object'); + var symbols = require('can-observe/src/-symbols'); + var observableStore = require('can-observe/src/-observable-store'); + var helpers = require('can-observe/src/-helpers'); + var isInteger = Number.isInteger || function (value) { + return typeof value === 'number' && isFinite(value) && Math.floor(value) === value; + }; + function didLengthChangeCauseDeletions(key, value, old) { + return key === 'length' && value < old; + } + var mutateMethods = { + 'push': function (arr, args) { + return [{ + index: arr.length - args.length, + deleteCount: 0, + insert: args, + type: 'splice' + }]; + }, + 'pop': function (arr) { + return [{ + index: arr.length, + deleteCount: 1, + insert: [], + type: 'splice' + }]; + }, + 'shift': function () { + return [{ + index: 0, + deleteCount: 1, + insert: [], + type: 'splice' + }]; + }, + 'unshift': function (arr, args) { + return [{ + index: 0, + deleteCount: 0, + insert: args, + type: 'splice' + }]; + }, + 'splice': function (arr, args) { + return [{ + index: args[0], + deleteCount: args[1], + insert: args.slice(2), + type: 'splice' + }]; + }, + 'sort': function (arr) { + return [{ + index: 0, + deleteCount: arr.length, + insert: arr, + type: 'splice' + }]; + }, + 'reverse': function (arr, args, old) { + return [{ + index: 0, + deleteCount: arr.length, + insert: arr, + type: 'splice' + }]; + } + }; + canReflect.eachKey(mutateMethods, function (makePatches, prop) { + var protoFn = Array.prototype[prop]; + var mutateMethod = function () { + var meta = this[symbols.metaSymbol], makeSideEffects = meta.preventSideEffects === 0, oldLength = meta.target.length; + meta.preventSideEffects++; + var ret = protoFn.apply(meta.target, arguments); + var patches = makePatches(meta.target, Array.from(arguments), oldLength); + if (makeSideEffects === true) { + mapBindings.dispatch.call(meta.proxy, { + type: 'length', + patches: patches + }, [ + meta.target.length, + oldLength + ]); + } + meta.preventSideEffects--; + return ret; + }; + observableStore.proxiedObjects.set(protoFn, mutateMethod); + observableStore.proxies.add(mutateMethod); + }); + Object.getOwnPropertyNames(Array.prototype).forEach(function (prop) { + var protoFn = Array.prototype[prop]; + if (observableStore.proxiedObjects.has(protoFn)) { + return; + } + if (prop !== 'constructor' && typeof protoFn === 'function') { + var arrayMethod = function () { + ObservationRecorder.add(this, symbols.patchesSymbol); + var meta = this[symbols.metaSymbol]; + meta.preventSideEffects++; + var ret = protoFn.apply(this, arguments); + meta.preventSideEffects--; + return meta.options.observe(ret); + }; + observableStore.proxiedObjects.set(protoFn, arrayMethod); + observableStore.proxies.add(arrayMethod); + } + }); + var proxyKeys = helpers.assignEverything(Object.create(null), makeObject.proxyKeys()); + var makeArray = { + observable: function (array, options) { + if (options.shouldRecordObservation === undefined) { + options.shouldRecordObservation = makeObject.shouldRecordObservationOnOwnAndMissingKeys; + } + var meta = { + target: array, + proxyKeys: options.proxyKeys !== undefined ? options.proxyKeys : Object.create(makeArray.proxyKeys()), + options: options, + preventSideEffects: 0 + }; + meta.proxyKeys[symbols.metaSymbol] = meta; + meta.proxy = new Proxy(array, { + get: makeObject.get.bind(meta), + set: makeArray.set.bind(meta), + ownKeys: makeObject.ownKeys.bind(meta), + deleteProperty: makeObject.deleteProperty.bind(meta), + meta: meta + }); + mapBindings.addHandlers(meta.proxy, meta); + return meta.proxy; + }, + proxyKeys: function () { + return proxyKeys; + }, + set: function (target, key, value, receiver) { + if (receiver !== this.proxy) { + return makeObject.setKey(receiver, key, value, this); + } + value = makeObject.getValueToSet(key, value, this); + var startingLength = target.length; + makeObject.setValueAndOnChange(key, value, this, function (key, value, meta, hadOwn, old) { + var patches = [{ + key: key, + type: hadOwn ? 'set' : 'add', + value: value + }]; + var numberKey = +key; + if (isInteger(numberKey)) { + if (!hadOwn && numberKey > startingLength) { + patches.push({ + index: startingLength, + deleteCount: 0, + insert: target.slice(startingLength), + type: 'splice' + }); + } else { + patches.push.apply(patches, mutateMethods.splice(target, [ + numberKey, + 1, + value + ])); + } + } + if (didLengthChangeCauseDeletions(key, value, old, meta)) { + patches.push({ + index: value, + deleteCount: old - value, + insert: [], + type: 'splice' + }); + } + mapBindings.dispatch.call(meta.proxy, { + type: key, + patches: patches, + keyChanged: !hadOwn ? key : undefined + }, [ + value, + old + ]); + }); + return true; + } + }; + module.exports = makeArray; +}); +/*can-event-queue@1.0.0#type/type*/ +define('can-event-queue/type/type', [ + 'require', + 'exports', + 'module', + 'can-reflect', + 'can-symbol', + 'can-key-tree', + 'can-queues' +], function (require, exports, module) { + var canReflect = require('can-reflect'); + var canSymbol = require('can-symbol'); + var KeyTree = require('can-key-tree'); + var queues = require('can-queues'); + var metaSymbol = canSymbol.for('can.meta'); + function addHandlers(obj, meta) { + if (!meta.lifecycleHandlers) { + meta.lifecycleHandlers = new KeyTree([ + Object, + Array + ]); + } + if (!meta.instancePatchesHandlers) { + meta.instancePatchesHandlers = new KeyTree([ + Object, + Array + ]); + } + } + function ensureMeta(obj) { + var meta = obj[metaSymbol]; + if (!meta) { + meta = {}; + canReflect.setKeyValue(obj, metaSymbol, meta); + } + addHandlers(obj, meta); + return meta; + } + var props = {}; + function onOffAndDispatch(symbolName, dispatchName, handlersName) { + props['can.on' + symbolName] = function (handler, queueName) { + ensureMeta(this)[handlersName].add([ + queueName || 'mutate', + handler + ]); + }; + props['can.off' + symbolName] = function (handler, queueName) { + ensureMeta(this)[handlersName].delete([ + queueName || 'mutate', + handler + ]); + }; + props['can.' + dispatchName] = function (instance, arg) { + queues.enqueueByQueue(ensureMeta(this)[handlersName].getNode([]), this, [ + instance, + arg + ]); + }; + } + onOffAndDispatch('InstancePatches', 'dispatchInstanceOnPatches', 'instancePatchesHandlers'); + onOffAndDispatch('InstanceBoundChange', 'dispatchInstanceBoundChange', 'lifecycleHandlers'); + function mixinTypeBindings(obj) { + return canReflect.assignSymbols(obj, props); + } + Object.defineProperty(mixinTypeBindings, 'addHandlers', { + enumerable: false, + value: addHandlers + }); + module.exports = mixinTypeBindings; +}); +/*can-observe@2.0.0-pre.22#src/-make-function*/ +define('can-observe/src/-make-function', [ + 'require', + 'exports', + 'module', + 'can-reflect', + 'can-observe/src/-make-object', + 'can-observe/src/-symbols', + 'can-observe/src/-observable-store', + 'can-event-queue/map/map', + 'can-event-queue/type/type', + 'can-observe/src/-helpers' +], function (require, exports, module) { + var canReflect = require('can-reflect'); + var makeObject = require('can-observe/src/-make-object'); + var symbols = require('can-observe/src/-symbols'); + var observableStore = require('can-observe/src/-observable-store'); + var mapBindings = require('can-event-queue/map/map'); + var typeBindings = require('can-event-queue/type/type'); + var helpers = require('can-observe/src/-helpers'); + var proxyKeys = helpers.assignEverything(Object.create(null), makeObject.proxyKeys()); + typeBindings(proxyKeys); + canReflect.assignSymbols(proxyKeys, { + 'can.defineInstanceKey': function (prop, value) { + this[symbols.metaSymbol].definitions[prop] = value; + } + }); + var makeFunction = { + observable: function (object, options) { + if (options.shouldRecordObservation === undefined) { + options.shouldRecordObservation = makeObject.shouldRecordObservationOnOwnAndMissingKeys; + } + var proxyKeys = Object.create(makeFunction.proxyKeys()); + var meta = { + target: object, + proxyKeys: proxyKeys, + options: options, + definitions: {}, + isClass: helpers.isClass(object), + preventSideEffects: 0 + }; + proxyKeys[symbols.metaSymbol] = meta; + meta.proxy = new Proxy(object, { + get: makeObject.get.bind(meta), + set: makeObject.set.bind(meta), + ownKeys: makeObject.ownKeys.bind(meta), + deleteProperty: makeObject.deleteProperty.bind(meta), + construct: makeFunction.construct.bind(meta), + apply: makeFunction.apply.bind(meta), + meta: meta + }); + mapBindings.addHandlers(meta.proxy, meta); + typeBindings.addHandlers(meta.proxy, meta); + observableStore.proxiedObjects.set(object, meta.proxy); + observableStore.proxies.add(meta.proxy); + if (meta.target.prototype && meta.target.prototype.constructor === meta.target) { + var prototype = meta.proxy.prototype; + prototype.constructor = meta.proxy; + } + return meta.proxy; + }, + construct: function (target, argumentsList, newTarget) { + var instanceTarget, key; + if (this.isClass) { + instanceTarget = Reflect.construct(target, argumentsList, newTarget); + for (key in this.definitions) { + Object.defineProperty(instanceTarget, key, this.definitions[key]); + } + return this.options.observe(instanceTarget); + } else { + instanceTarget = Object.create(this.proxy.prototype); + for (key in this.definitions) { + Object.defineProperty(instanceTarget, key, this.definitions[key]); + } + var instance = this.options.observe(instanceTarget); + instance[symbols.metaSymbol].preventSideEffects++; + var res = target.apply(instance, argumentsList); + instance[symbols.metaSymbol].preventSideEffects--; + if (res) { + return res; + } else { + return instance; + } + } + }, + apply: function (target, thisArg, argumentsList) { + var ret = this.target.apply(thisArg, argumentsList); + return this.options.observe(ret); + }, + proxyKeys: function () { + return proxyKeys; + } + }; + module.exports = makeFunction; +}); +/*can-observe@2.0.0-pre.22#src/-make-observe*/ +define('can-observe/src/-make-observe', [ + 'require', + 'exports', + 'module', + 'can-reflect', + 'can-observe/src/-observable-store', + 'can-observe/src/-helpers' +], function (require, exports, module) { + var canReflect = require('can-reflect'); + var observables = require('can-observe/src/-observable-store'); + var helpers = require('can-observe/src/-helpers'); + var makeObserve = { + observe: function (value) { + if (canReflect.isPrimitive(value)) { + return value; + } + var observable = observables.proxiedObjects.get(value); + if (observable) { + return observable; + } + if (observables.proxies.has(value)) { + return value; + } + if (helpers.isBuiltInButNotArrayOrPlainObject(value)) { + return value; + } + if (typeof value === 'function') { + observable = makeObserve.function(value); + } else if (helpers.inheritsFromArray(value)) { + observable = makeObserve.array(value); + } else { + observable = makeObserve.object(value); + } + observables.proxiedObjects.set(value, observable); + observables.proxies.add(observable); + return observable; + }, + 'object': null, + 'array': null, + 'function': null + }; + module.exports = makeObserve; +}); +/*can-define-lazy-value@1.0.1#define-lazy-value*/ +define('can-define-lazy-value', function (require, exports, module) { + module.exports = function defineLazyValue(obj, prop, initializer, writable) { + Object.defineProperty(obj, prop, { + configurable: true, + get: function () { + Object.defineProperty(this, prop, { + value: undefined, + writable: true + }); + var value = initializer.call(this, obj, prop); + Object.defineProperty(this, prop, { + value: value, + writable: !!writable + }); + return value; + }, + set: function (value) { + Object.defineProperty(this, prop, { + value: value, + writable: !!writable + }); + return value; + } + }); + }; +}); +/*can-event-queue@1.0.0#value/value*/ +define('can-event-queue/value/value', [ + 'require', + 'exports', + 'module', + 'can-queues', + 'can-key-tree', + 'can-reflect', + 'can-define-lazy-value', + 'can-event-queue/dependency-record/merge' +], function (require, exports, module) { + var queues = require('can-queues'); + var KeyTree = require('can-key-tree'); + var canReflect = require('can-reflect'); + var defineLazyValue = require('can-define-lazy-value'); + var mergeDependencyRecords = require('can-event-queue/dependency-record/merge'); + var properties = { + on: function (handler, queue) { + this.handlers.add([ + queue || 'mutate', + handler + ]); + }, + off: function (handler, queueName) { + if (handler === undefined) { + if (queueName === undefined) { + this.handlers.delete([]); + } else { + this.handlers.delete([queueName]); + } + } else { + this.handlers.delete([ + queueName || 'mutate', + handler + ]); + } + } + }; + var symbols = { + 'can.onValue': properties.on, + 'can.offValue': properties.off, + 'can.dispatch': function (value, old) { + queues.enqueueByQueue(this.handlers.getNode([]), this, [ + value, + old + ]); + }, + 'can.getWhatIChange': function getWhatIChange() { + }, + 'can.isBound': function isBound() { + return this.handlers.size() > 0; + } + }; + function defineLazyHandlers() { + return new KeyTree([ + Object, + Array + ], { + onFirst: this.onBound !== undefined && this.onBound.bind(this), + onEmpty: this.onUnbound !== undefined && this.onUnbound.bind(this) + }); + } + var mixinValueEventBindings = function (obj) { + canReflect.assign(obj, properties); + canReflect.assignSymbols(obj, symbols); + defineLazyValue(obj, 'handlers', defineLazyHandlers, true); + return obj; + }; + mixinValueEventBindings.addHandlers = function (obj, callbacks) { + console.warn('can-event-queue/value: Avoid using addHandlers. Add onBound and onUnbound methods instead.'); + obj.handlers = new KeyTree([ + Object, + Array + ], callbacks); + return obj; + }; + module.exports = mixinValueEventBindings; +}); +/*can-observation@4.0.0#recorder-dependency-helpers*/ +define('can-observation/recorder-dependency-helpers', [ + 'require', + 'exports', + 'module', + 'can-reflect' +], function (require, exports, module) { + var canReflect = require('can-reflect'); + function addNewKeyDependenciesIfNotInOld(event) { + if (this.oldEventSet === undefined || this.oldEventSet['delete'](event) === false) { + canReflect.onKeyValue(this.observable, event, this.onDependencyChange, 'notify'); + } + } + function addObservablesNewKeyDependenciesIfNotInOld(eventSet, observable) { + eventSet.forEach(addNewKeyDependenciesIfNotInOld, { + onDependencyChange: this.onDependencyChange, + observable: observable, + oldEventSet: this.oldDependencies.keyDependencies.get(observable) + }); + } + function removeKeyDependencies(event) { + canReflect.offKeyValue(this.observable, event, this.onDependencyChange, 'notify'); + } + function removeObservablesKeyDependencies(oldEventSet, observable) { + oldEventSet.forEach(removeKeyDependencies, { + onDependencyChange: this.onDependencyChange, + observable: observable + }); + } + function addValueDependencies(observable) { + if (this.oldDependencies.valueDependencies.delete(observable) === false) { + canReflect.onValue(observable, this.onDependencyChange, 'notify'); + } + } + function removeValueDependencies(observable) { + canReflect.offValue(observable, this.onDependencyChange, 'notify'); + } + module.exports = { + updateObservations: function (observationData) { + observationData.newDependencies.keyDependencies.forEach(addObservablesNewKeyDependenciesIfNotInOld, observationData); + observationData.oldDependencies.keyDependencies.forEach(removeObservablesKeyDependencies, observationData); + observationData.newDependencies.valueDependencies.forEach(addValueDependencies, observationData); + observationData.oldDependencies.valueDependencies.forEach(removeValueDependencies, observationData); + }, + stopObserving: function (observationReciever, onDependencyChange) { + observationReciever.keyDependencies.forEach(removeObservablesKeyDependencies, { onDependencyChange: onDependencyChange }); + observationReciever.valueDependencies.forEach(removeValueDependencies, { onDependencyChange: onDependencyChange }); + } + }; +}); +/*can-observation@4.0.0#temporarily-bind*/ +define('can-observation/temporarily-bind', [ + 'require', + 'exports', + 'module', + 'can-reflect' +], function (require, exports, module) { + var canReflect = require('can-reflect'); + var temporarilyBoundNoOperation = function () { + }; + var observables; + var unbindTemporarilyBoundValue = function () { + for (var i = 0, len = observables.length; i < len; i++) { + canReflect.offValue(observables[i], temporarilyBoundNoOperation); + } + observables = null; + }; + function temporarilyBind(compute) { + var computeInstance = compute.computeInstance || compute; + canReflect.onValue(computeInstance, temporarilyBoundNoOperation); + if (!observables) { + observables = []; + setTimeout(unbindTemporarilyBoundValue, 10); + } + observables.push(computeInstance); + } + module.exports = temporarilyBind; +}); +/*can-observation@4.0.0#can-observation*/ +define('can-observation', [ + 'require', + 'exports', + 'module', + 'can-namespace', + 'can-reflect', + 'can-queues', + 'can-observation-recorder', + 'can-symbol', + 'can-log/dev/dev', + 'can-event-queue/value/value', + 'can-observation/recorder-dependency-helpers', + 'can-observation/temporarily-bind' +], function (require, exports, module) { + (function (global, require, exports, module) { + var namespace = require('can-namespace'); + var canReflect = require('can-reflect'); + var queues = require('can-queues'); + var ObservationRecorder = require('can-observation-recorder'); + var canSymbol = require('can-symbol'); + var dev = require('can-log/dev/dev'); + var valueEventBindings = require('can-event-queue/value/value'); + var recorderHelpers = require('can-observation/recorder-dependency-helpers'); + var temporarilyBind = require('can-observation/temporarily-bind'); + var dispatchSymbol = canSymbol.for('can.dispatch'); + var getChangesSymbol = canSymbol.for('can.getChangesDependencyRecord'); + var getValueDependenciesSymbol = canSymbol.for('can.getValueDependencies'); + function Observation(func, context, options) { + this.func = func; + this.context = context; + this.options = options || { + priority: 0, + isObservable: true + }; + this.bound = false; + this.newDependencies = ObservationRecorder.makeDependenciesRecord(); + this.oldDependencies = null; + var self = this; + this.onDependencyChange = function (newVal) { + self.dependencyChange(this, newVal); + }; + this.update = this.update.bind(this); + } + valueEventBindings(Observation.prototype); + canReflect.assign(Observation.prototype, { + onBound: function () { + this.bound = true; + this.oldDependencies = this.newDependencies; + ObservationRecorder.start(); + this.value = this.func.call(this.context); + this.newDependencies = ObservationRecorder.stop(); + recorderHelpers.updateObservations(this); + }, + dependencyChange: function (context, args) { + if (this.bound === true) { + queues.deriveQueue.enqueue(this.update, this, [], { priority: this.options.priority }); + } + }, + update: function () { + if (this.bound === true) { + var oldValue = this.value; + this.oldValue = null; + this.onBound(); + if (oldValue !== this.value) { + this[dispatchSymbol](this.value, oldValue); + } + } + }, + onUnbound: function () { + this.bound = false; + recorderHelpers.stopObserving(this.newDependencies, this.onDependencyChange); + this.newDependencies = ObservationRecorder.makeDependenciesRecorder(); + }, + get: function () { + if (this.options.isObservable && ObservationRecorder.isRecording()) { + ObservationRecorder.add(this); + if (!this.bound) { + Observation.temporarilyBind(this); + } + } + if (this.bound === true) { + if (queues.deriveQueue.tasksRemainingCount() > 0) { + Observation.updateChildrenAndSelf(this); + } + return this.value; + } else { + return this.func.call(this.context); + } + }, + hasDependencies: function () { + var newDependencies = this.newDependencies; + return this.bound ? newDependencies.valueDependencies.size + newDependencies.keyDependencies.size > 0 : undefined; + }, + log: function () { + } + }); + canReflect.assignSymbols(Observation.prototype, { + 'can.getValue': Observation.prototype.get, + 'can.isValueLike': true, + 'can.isMapLike': false, + 'can.isListLike': false, + 'can.valueHasDependencies': Observation.prototype.hasDependencies, + 'can.getValueDependencies': function () { + if (this.bound === true) { + var deps = this.newDependencies, result = {}; + if (deps.keyDependencies.size) { + result.keyDependencies = deps.keyDependencies; + } + if (deps.valueDependencies.size) { + result.valueDependencies = deps.valueDependencies; + } + return result; + } + return undefined; + }, + 'can.getPriority': function () { + return this.options.priority; + }, + 'can.setPriority': function (priority) { + this.options.priority = priority; + } + }); + Observation.updateChildrenAndSelf = function (observation) { + if (observation.update !== undefined && queues.deriveQueue.isEnqueued(observation.update) === true) { + queues.deriveQueue.flushQueuedTask(observation.update); + return true; + } + if (observation[getValueDependenciesSymbol]) { + var childHasChanged = false; + var valueDependencies = observation[getValueDependenciesSymbol]().valueDependencies || []; + valueDependencies.forEach(function (observable) { + if (Observation.updateChildrenAndSelf(observable) === true) { + childHasChanged = true; + } + }); + return childHasChanged; + } else { + return false; + } + }; + var alias = { addAll: 'addMany' }; + [ + 'add', + 'addAll', + 'ignore', + 'trap', + 'trapsCount', + 'isRecording' + ].forEach(function (methodName) { + Observation[methodName] = function () { + var name = alias[methodName] ? alias[methodName] : methodName; + console.warn('can-observation: Call ' + name + '() on can-observation-recorder.'); + return ObservationRecorder[name].apply(this, arguments); + }; + }); + Observation.prototype.start = function () { + console.warn('can-observation: Use .on and .off to bind.'); + return this.onBound(); + }; + Observation.prototype.stop = function () { + console.warn('can-observation: Use .on and .off to bind.'); + return this.onUnbound(); + }; + Observation.temporarilyBind = temporarilyBind; + module.exports = namespace.Observation = Observation; + }(function () { + return this; + }(), require, exports, module)); +}); +/*can-observe@2.0.0-pre.22#src/-memoize-getter*/ +define('can-observe/src/-memoize-getter', [ + 'require', + 'exports', + 'module', + 'can-observation', + 'can-observation-recorder', + 'can-observe/src/-observable-store' +], function (require, exports, module) { + var Observation = require('can-observation'); + var ObservationRecorder = require('can-observation-recorder'); + var observableStore = require('can-observe/src/-observable-store'); + function MemoizedGetterObservationData(instance, prop, getter) { + this.prop = prop; + this.instance = instance; + this.forward = this.forward.bind(this); + this.observation = new Observation(getter, instance, { isObservable: false }); + } + MemoizedGetterObservationData.prototype.bind = function (observationData) { + this.bindingCount++; + if (this.bindingCount === 1) { + this.observation.on(this.forward, 'notify'); + } + }; + MemoizedGetterObservationData.prototype.unbind = function (observationData) { + this.bindingCount--; + if (this.bindingCount === 0) { + this.observation.off(this.forward, 'notify'); + } + }; + MemoizedGetterObservationData.prototype.forward = function (newValue, oldValue) { + this.instance.dispatch({ + type: this.prop, + target: this.instance + }, [ + newValue, + oldValue + ]); + }; + MemoizedGetterObservationData.prototype.bindingCount = 0; + module.exports = function memoize(Type, prop, definition) { + var instanceToObservationData = new WeakMap(); + function getObservationDataFor(instance) { + var observationData = instanceToObservationData.get(instance); + if (!observationData) { + observationData = new MemoizedGetterObservationData(instance, prop, definition.get); + instanceToObservationData.set(instance, observationData); + } + return observationData; + } + Object.defineProperty(Type, prop, { + enumerable: definition.enumerable, + get: function memoized() { + var instance = observableStore.proxiedObjects.get(this) || this; + var observationData = getObservationDataFor(instance); + ObservationRecorder.add(instance, prop.toString()); + if (!observationData.observation.bound && ObservationRecorder.isRecording()) { + Observation.temporarilyBind(observationData.observation); + } + return observationData.observation.get(); + } + }); + return getObservationDataFor; + }; +}); +/*can-observe@2.0.0-pre.22#src/-getter-helpers*/ +define('can-observe/src/-getter-helpers', [ + 'require', + 'exports', + 'module', + 'can-symbol', + 'can-event-queue/type/type', + 'can-reflect', + 'can-observe/src/-memoize-getter', + 'can-queues', + 'can-event-queue/map/map' +], function (require, exports, module) { + var canSymbol = require('can-symbol'); + var definitionsSymbol = canSymbol.for('can.typeDefinitions'); + var typeEventMixin = require('can-event-queue/type/type'); + var canReflect = require('can-reflect'); + var memoizeGetter = require('can-observe/src/-memoize-getter'); + var queues = require('can-queues'); + var eventMixin = require('can-event-queue/map/map'); + var computedDefinitionsSymbol = canSymbol.for('can.computedDefinitions'); + var metaSymbol = canSymbol.for('can.meta'); + var getterHelpers = { + ensureTypeDefinition: function (obj) { + var typeDefs = obj.prototype[definitionsSymbol]; + if (!typeDefs) { + typeDefs = obj.prototype[definitionsSymbol] = Object.create(null); + } + return typeDefs; + }, + shouldRecordObservationOnAllKeysExceptFunctionsOnProto: function (keyInfo, meta) { + return meta.preventSideEffects === 0 && !keyInfo.isAccessor && (keyInfo.targetHasOwnKey || !keyInfo.protoHasKey && !Object.isSealed(meta.target) || keyInfo.protoHasKey && typeof targetValue !== 'function'); + }, + addMethodsAndSymbols: function (Type) { + typeEventMixin(Type); + canReflect.assignSymbols(Type, { + 'can.defineInstanceKey': function (prop, value) { + getterHelpers.ensureTypeDefinition(this)[prop] = value; + }, + 'can.dispatchInstanceBoundChange': function (obj, isBound) { + var meta = this[metaSymbol]; + if (meta) { + var lifecycleHandlers = meta.lifecycleHandlers; + if (lifecycleHandlers) { + queues.enqueueByQueue(lifecycleHandlers.getNode([]), this, [ + obj, + isBound + ]); + } + } + } + }); + Type.prototype.addEventListener = function (key, handler, queue) { + var getObservation = this[computedDefinitionsSymbol][key]; + if (getObservation !== undefined) { + getObservation(this).bind(); + } + return eventMixin.addEventListener.call(this, key, handler, queue); + }; + Type.prototype.removeEventListener = function (key, handler, queue) { + var getObservation = this[computedDefinitionsSymbol][key]; + if (getObservation !== undefined) { + getObservation(this).unbind(); + } + return eventMixin.removeEventListener.call(this, key, handler, queue); + }; + }, + setupComputedProperties: function (prototype) { + var computed = {}; + Object.getOwnPropertyNames(prototype).forEach(function (prop) { + var descriptor = Object.getOwnPropertyDescriptor(prototype, prop); + if (descriptor.get !== undefined) { + var getObservationData = memoizeGetter(prototype, prop, descriptor); + computed[prop] = getObservationData; + } + }); + return computed; + }, + addMemoizedGetterBindings: function (proxyKeys) { + return canReflect.assignSymbols(proxyKeys, { + 'can.onKeyValue': function (key, handler, queue) { + var getObservation = this[computedDefinitionsSymbol][key]; + if (getObservation !== undefined) { + getObservation(this).bind(); + } + var handlers = this[metaSymbol].handlers; + handlers.add([ + key, + 'onKeyValue', + queue || 'notify', + handler + ]); + }, + 'can.offKeyValue': function (key, handler, queue) { + var getObservation = this[computedDefinitionsSymbol][key]; + if (getObservation !== undefined) { + getObservation(this).unbind(); + } + var handlers = this[metaSymbol].handlers; + handlers.delete([ + key, + 'onKeyValue', + queue || 'notify', + handler + ]); + } + }); + } + }; + module.exports = getterHelpers; +}); +/*can-observe@2.0.0-pre.22#object/object*/ +define('can-observe/object/object', [ + 'require', + 'exports', + 'module', + 'can-reflect', + 'can-symbol', + 'can-observe/src/-make-observe', + 'can-event-queue/map/map', + 'can-observe/src/-helpers', + 'can-observe/src/-make-object', + 'can-observe/src/-observable-store', + 'can-observe/src/-getter-helpers' +], function (require, exports, module) { + var canReflect = require('can-reflect'); + var canSymbol = require('can-symbol'); + var makeObserve = require('can-observe/src/-make-observe'); + var eventMixin = require('can-event-queue/map/map'); + var helpers = require('can-observe/src/-helpers'); + var makeObject = require('can-observe/src/-make-object'); + var observableStore = require('can-observe/src/-observable-store'); + var definitionsSymbol = canSymbol.for('can.typeDefinitions'); + var getterHelpers = require('can-observe/src/-getter-helpers'); + var computedDefinitionsSymbol = canSymbol.for('can.computedDefinitions'); + var proxyKeys = helpers.assignEverything({}, makeObject.proxyKeys()); + getterHelpers.addMemoizedGetterBindings(proxyKeys); + var ObserveObject = function (props) { + var prototype = Object.getPrototypeOf(this); + if (prototype[computedDefinitionsSymbol] === undefined) { + prototype[computedDefinitionsSymbol] = getterHelpers.setupComputedProperties(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: getterHelpers.shouldRecordObservationOnAllKeysExceptFunctionsOnProto + }); + observableStore.proxiedObjects.set(sourceInstance, observable); + observableStore.proxies.add(observable); + return observable; + }; + eventMixin(ObserveObject.prototype); + getterHelpers.addMethodsAndSymbols(ObserveObject); + ObserveObject.extend = helpers.makeSimpleExtender(ObserveObject); + module.exports = ObserveObject; +}); +/*can-observe@2.0.0-pre.22#array/array*/ +define('can-observe/array/array', [ + 'require', + 'exports', + 'module', + 'can-symbol', + 'can-observe/src/-make-array', + 'can-observe/src/-make-observe', + 'can-event-queue/map/map', + 'can-observe/src/-helpers', + 'can-observe/src/-observable-store', + 'can-observe/src/-getter-helpers' +], function (require, exports, module) { + var canSymbol = require('can-symbol'); + var makeArray = require('can-observe/src/-make-array'); + var makeObserve = require('can-observe/src/-make-observe'); + var eventMixin = require('can-event-queue/map/map'); + var helpers = require('can-observe/src/-helpers'); + var observableStore = require('can-observe/src/-observable-store'); + var getterHelpers = require('can-observe/src/-getter-helpers'); + var definitionsSymbol = canSymbol.for('can.typeDefinitions'); + var computedDefinitionsSymbol = canSymbol.for('can.computedDefinitions'); + var proxyKeys = helpers.assignEverything({}, makeArray.proxyKeys()); + getterHelpers.addMemoizedGetterBindings(proxyKeys); + var ObserveArray; + if (false) { + } else { + var ObserveArray = function (items) { + var prototype = Object.getPrototypeOf(this); + if (prototype[computedDefinitionsSymbol] === undefined) { + prototype[computedDefinitionsSymbol] = getterHelpers.setupComputedProperties(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: getterHelpers.shouldRecordObservationOnAllKeysExceptFunctionsOnProto + }); + observableStore.proxiedObjects.set(instance, observable); + observableStore.proxies.add(observable); + return observable; + }; + ObserveArray.prototype = Object.create(Array.prototype); + } + eventMixin(ObserveArray.prototype); + getterHelpers.addMethodsAndSymbols(ObserveArray); + ObserveArray.extend = helpers.makeSimpleExtender(ObserveArray); + module.exports = ObserveArray; +}); +/*can-observe@2.0.0-pre.22#can-observe*/ +define('can-observe', [ + 'require', + 'exports', + 'module', + 'can-observe/src/-make-object', + 'can-observe/src/-make-array', + 'can-observe/src/-make-function', + 'can-observe/src/-make-observe', + 'can-observe/object/object', + 'can-observe/array/array' +], function (require, exports, module) { + var makeObject = require('can-observe/src/-make-object'); + var makeArray = require('can-observe/src/-make-array'); + var makeFunction = require('can-observe/src/-make-function'); + var makeObserve = require('can-observe/src/-make-observe'); + var ObserveObject = require('can-observe/object/object'); + var ObserveArray = require('can-observe/array/array'); + 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; +}); +/*[global-shim-end]*/ +(function(global) { // jshint ignore:line + global._define = global.define; + global.define = global.define.orig; +} +)(typeof self == "object" && self.Object == Object ? self : window); \ No newline at end of file