{"version":3,"sources":["webpack:///./node_modules/aurelia-typed-observable-plugin/dist/native-modules/index.js"],"names":["coerceFunctions","none","a","number","Number","string","boolean","booleanAttr","val","date","d","Date","isNaN","getTime","coerceFunctionMap","Map","Boolean","String","mapCoerceFunction","type","strType","coerceFunction","coerce","set","warn","name","prototype","setCoerce","this","undefined","Object","keys","setValue","newValue","oldValue","currentValue","coercedValue","publishing","notqueued","taskQueue","flushing","call","queueMicroTask","createObserver","viewModel","initialValue","selfSubscriber","defaultValue","changeHandlerName","changeHandler","hasOptions","propertyChanged","Error","observer","owner","_createDynamicProperty","observerLookup","behaviorHandlesBind","attribute","boundProperties","info","defineProperty","configurable","enumerable","get","getValue","bind","binding","createBinding","push","_usePropertyType","bindable","nameOrTargetOrConfig","key","descriptor","deco","target","key2","descriptor2","propType","actualTarget","constructor","r","getOrCreateOwn","resource","getOwn","propertyType","coerceType","registerWith","usePropertyType","shouldUsePropertyType","createTypedBindable","forEach","observableLogger","_usePropertyType$1","observable","config","isClassDecorator","innerPropertyName","innerPropertyDescriptor","writable","initValue","value","callbackName","initializer","Reflect","dependencies","t","k","usePropertyType$1","shouldUsePropType","createTypedObservable"],"mappings":"0FAAA,ydAIIA,EAAkB,CAClBC,KAAM,SAAUC,GACZ,OAAOA,GAEXC,OAAQ,SAAUD,GACd,OAAOE,OAAOF,IAElBG,OAAQ,SAAUH,GACd,MAAO,GAAKA,GAEhBI,QAAS,SAAUJ,GACf,QAASA,GAEbK,YAAa,SAAUC,GACnB,SAAOA,GAAe,KAARA,IAElBC,KAAM,SAAUD,GAGZ,GAAIA,QACA,OAAO,KAEX,IAAIE,EAAI,IAAIC,KAAKH,GACjB,OAAOI,MAAMF,EAAEG,WAAa,KAAOH,IAGvCI,EAAoB,IAAIC,IAAI,CAC5B,CAACC,QAAS,WACV,CAACC,OAAQ,UACT,CAACN,KAAM,QACP,CAACP,OAAQ,YAQb,SAASc,EAAkBC,EAAMC,EAASC,GACtCA,EAAiBA,GAAkBF,EAAKG,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sE,GAAqB9D,EAC1BqE,QAAQ5C,eAAejC,KAAMsE,EAAmB,CAAEnC,YAAY,IAC1DnC,KAAK2E,IACL3E,KAAK2E,GAAcnE,EAAcF,EAAUuC,KAKnDC,EAAWV,IAAI0C,aAAe,CAACR,IAC3BD,EAIA,OAAOvB,EAHP+B,QAAQ5C,eAAee,EAAQH,EAAKC,GAgB5C,YAAY7C,IAAR4C,EACO,SAAUkC,EAAGC,EAAGlG,GAAK,OAAOiE,EAAKgC,EAAGC,EAAGlG,EAAG8D,IAS9CG,EAAKH,EAAsBC,EAAKC,IAoB3C,SAASmC,EAAkBC,GACvBhB,IAAuBgB,EAM3B,SAASC,EAAsB5F,GAC3B,OAAO4E,EAAW5E,GAAQ,SAAUqD,EAAsBC,EAAKC,GAC3D,YAA6B7C,IAAzB2C,EAUOuB,EAAW,CAAEzE,OAAQH,SAEpBU,IAAR4C,IAaAD,EAAuD,iBAAzBA,EAAoC,CAAE/C,KAAM+C,GAAyBA,GAC9ElD,OAASH,EACvB4E,EAAWvB,IAOfuB,EAAW,CAAEzE,OAAQH,GAArB4E,CAA6BvB,EAAsBC,EAAKC,IA7DvE,CAAC,SAAU,SAAU,UAAW,QAAQkB,QAAQmB","file":"npm.aurelia-typed-observable-plugin.e560969e3332e7a5f12c.js","sourcesContent":["import { getLogger } from 'aurelia-logging';\nimport { BehaviorPropertyObserver, BindableProperty, HtmlBehaviorResource } from 'aurelia-templating';\nimport { metadata } from 'aurelia-metadata';\n\nvar coerceFunctions = {\n none: function (a) {\n return a;\n },\n number: function (a) {\n return Number(a);\n },\n string: function (a) {\n return '' + a;\n },\n boolean: function (a) {\n return !!a;\n },\n booleanAttr: function (val) {\n return val || val === '' ? true : false;\n },\n date: function (val) {\n // Invalid date instances are quite problematic\n // so we need to deal with it properly by default\n if (val === null || val === undefined) {\n return null;\n }\n var d = new Date(val);\n return isNaN(d.getTime()) ? null : d;\n }\n};\nvar coerceFunctionMap = new Map([\n [Boolean, 'boolean'],\n [String, 'string'],\n [Date, 'date'],\n [Number, 'number'],\n]);\n/**\n * Map a class to a string for typescript property coerce\n * @param type the property class to register\n * @param strType the string that represents class in the lookup\n * @param coerceFunction coerce function to register with param strType\n */\nfunction mapCoerceFunction(type, strType, coerceFunction) {\n coerceFunction = coerceFunction || type.coerce;\n if (typeof strType !== 'string' || typeof coerceFunction !== 'function') {\n getLogger('map-coerce-function')\n .warn(\"Bad attempt at mapping coerce function for type: \" + type.name + \" to: \" + strType);\n return;\n }\n coerceFunctions[strType] = coerceFunction;\n coerceFunctionMap.set(type, strType);\n}\n\n// tslint:disable: interface-name no-invalid-this no-non-null-assertion\nBehaviorPropertyObserver.prototype.setCoerce = function (coerce) {\n this.coerce = typeof coerce === 'function' ? coerce : coerceFunctions[coerce];\n if (this.coerce === undefined) {\n getLogger('behavior-property-observer')\n .warn(\"Invalid coerce instruction. Should be either one of \" + Object.keys(coerceFunctions) + \" or a function.\");\n }\n};\n/**\n * Slightly override the builtin implementation that will handle coercion\n */\nBehaviorPropertyObserver.prototype.setValue = function (newValue) {\n var oldValue = this.currentValue;\n var coercedValue = this.coerce === undefined ? newValue : this.coerce(newValue);\n if (oldValue !== coercedValue) {\n this.oldValue = oldValue;\n this.currentValue = coercedValue;\n if (this.publishing && this.notqueued) {\n if (this.taskQueue.flushing) {\n this.call();\n }\n else {\n this.notqueued = false;\n this.taskQueue.queueMicroTask(this);\n }\n }\n }\n};\nBindableProperty.prototype.createObserver = function (viewModel) {\n var selfSubscriber = null;\n var defaultValue = this.defaultValue;\n var changeHandlerName = this.changeHandler;\n var name = this.name;\n var initialValue;\n if (this.hasOptions) {\n return undefined;\n }\n if (changeHandlerName in viewModel) {\n if ('propertyChanged' in viewModel) {\n selfSubscriber = function (newValue, oldValue) {\n viewModel[changeHandlerName](newValue, oldValue);\n viewModel.propertyChanged(name, newValue, oldValue);\n };\n }\n else {\n selfSubscriber = function (newValue, oldValue) { return viewModel[changeHandlerName](newValue, oldValue); };\n }\n }\n else if ('propertyChanged' in viewModel) {\n selfSubscriber = function (newValue, oldValue) { return viewModel.propertyChanged(name, newValue, oldValue); };\n }\n else if (changeHandlerName !== null) {\n throw new Error(\"Change handler \" + changeHandlerName + \" was specified but not declared on the class.\");\n }\n if (defaultValue !== undefined) {\n initialValue = typeof defaultValue === 'function' ? defaultValue.call(viewModel) : defaultValue;\n }\n var observer = new BehaviorPropertyObserver(this.owner.taskQueue, viewModel, this.name, selfSubscriber, initialValue);\n if (this.coerce !== undefined) {\n observer.setCoerce(this.coerce);\n observer.currentValue = observer.oldValue = observer.coerce === undefined ? observer.currentValue : observer.coerce(initialValue);\n }\n return observer;\n};\nBindableProperty.prototype._createDynamicProperty = function (viewModel, observerLookup, behaviorHandlesBind, name, attribute, boundProperties) {\n var changeHandlerName = name + \"Changed\";\n var selfSubscriber = null;\n var observer;\n var info;\n if (changeHandlerName in viewModel) {\n if ('propertyChanged' in viewModel) {\n selfSubscriber = function (newValue, oldValue) {\n viewModel[changeHandlerName](newValue, oldValue);\n viewModel.propertyChanged(name, newValue, oldValue);\n };\n }\n else {\n selfSubscriber = function (newValue, oldValue) { return viewModel[changeHandlerName](newValue, oldValue); };\n }\n }\n else if ('propertyChanged' in viewModel) {\n selfSubscriber = function (newValue, oldValue) { return viewModel.propertyChanged(name, newValue, oldValue); };\n }\n observer = observerLookup[name] = new BehaviorPropertyObserver(this.owner.taskQueue, viewModel, name, selfSubscriber, undefined);\n observer.setCoerce(this.coerce);\n observer.currentValue = observer.oldValue = observer.coerce === undefined ? observer.currentValue : observer.coerce(undefined);\n Object.defineProperty(viewModel, name, {\n configurable: true,\n enumerable: true,\n get: observer.getValue.bind(observer),\n set: observer.setValue.bind(observer)\n });\n if (behaviorHandlesBind) {\n observer.selfSubscriber = null;\n }\n if (typeof attribute === 'string') {\n viewModel[name] = attribute;\n observer.call();\n }\n else if (attribute) {\n info = { observer: observer, binding: attribute.createBinding(viewModel) };\n boundProperties.push(info);\n }\n observer.publishing = true;\n observer.selfSubscriber = selfSubscriber;\n};\n\nvar _usePropertyType = false;\n/**\n * Decorator: Specifies that a property is bindable through HTML.\n * @param nameOrTargetOrConfig The name of the property, or a configuration object.\n * This has Object in its type to avoid breaking change.\n * Idealy it should be `string | BindablePropertyConfig`\n */\n// tslint:disable-next-line:no-shadowed-variable\nvar bindable = function bindable(nameOrTargetOrConfig, key, descriptor) {\n var deco = function (target, key2, descriptor2) {\n /**\n * key2 = truthy => decorated on a class field\n * key2 = falsy => decorated on a class\n */\n var actualTarget = key2 ? target.constructor : target;\n var r = metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, actualTarget);\n var prop;\n var propType;\n if (key2) { //is it on a property or a class?\n nameOrTargetOrConfig = nameOrTargetOrConfig || {};\n nameOrTargetOrConfig.name = key2;\n /**\n * Support for Typescript decorator, with metadata on property type.\n * Will check for typing only when user didn't explicitly set coerce + turn on the options\n *\n * If key 2 is truthy, it's a decorator on class field, which means target is prototype\n */\n if (nameOrTargetOrConfig.coerce === undefined && _usePropertyType) {\n propType = metadata.getOwn(metadata.propertyType, target, key2);\n if (propType) {\n var coerceType = coerceFunctionMap.get(propType);\n if (coerceType === undefined) {\n getLogger('@bindable decorator')\n .warn(\"Invalid coerce instruction. Should be either one of \" + Object.keys(coerceFunctions) + \" or a function.\");\n }\n nameOrTargetOrConfig.coerce = coerceType || 'none';\n }\n }\n }\n prop = new BindableProperty(nameOrTargetOrConfig);\n return prop.registerWith(actualTarget, r, descriptor2);\n };\n if (!nameOrTargetOrConfig) {\n /**\n * placed on property initializer with parens, without any params\n * @example:\n * class ViewModel {\n * @bindable() property\n * }\n * @bindable() class ViewModel {}\n */\n return deco;\n }\n if (key) {\n /**\n * placed on a property initializer without parens\n * @example\n * class ViewModel {\n * @bindable property\n * }\n *\n */\n var target = nameOrTargetOrConfig;\n nameOrTargetOrConfig = undefined;\n return deco(target, key, descriptor);\n }\n /**\n * placed on a class with parens and config\n * @example\n * @bindable({ ... })\n * class MyViewModel {}\n */\n return deco;\n};\n['string', 'number', 'boolean', 'booleanAttr', 'date'].forEach(createTypedBindable);\n/**\n * Used to allow user to automatically pickup property type\n * Can be used with typescript emit metadata in compiler settings, or with `Reflect.metadata('design:type', PropertyTypeClass)` decorator\n */\nfunction usePropertyType(shouldUsePropertyType) {\n _usePropertyType = shouldUsePropertyType;\n}\n/**\n * Create a new fluent syntax bindable decorator ex: builtin: `@bindable.string`, custom: `@bindable.customType`\n * Need to use together with setting the type in `coerceFunctions`:\n *\n * ```js\n * import {\n * createTypedBindable,\n * coerceFunctions\n * } from 'aurelia-framework'\n *\n * // create the typed bindable\n * createTypedBindable('point'); // => enable `@bindable.point`\n * // Set the instruction\n * coerceFunctions.point = function(value: string) {\n * // convert to point from value\n * }\n * ```\n *\n * @param type The type to added to bindable for fluent syntax.\n */\nfunction createTypedBindable(type) {\n /**\n * There no attempts to protect user from mis-using the decorators.\n * ex. @observable({}, accidentParam) class SomeClass {}\n * If we have some flag to use in if block, which can be remove at build time, it would be great.\n */\n return bindable[type] = function (nameOrTargetOrConfig, key, descriptor) {\n if (nameOrTargetOrConfig === undefined) {\n /**\n * MyClass {\n * @bindable.number() num\n * }\n */\n return bindable({ coerce: type });\n }\n if (key === undefined) {\n /**\n * @bindable.number('num')\n * class MyClass {}\n *\n * @bindable.number({...})\n * class MyClass\n *\n * class MyClass {\n * @bindable.number({...})\n * num\n * }\n */\n nameOrTargetOrConfig = typeof nameOrTargetOrConfig === 'string' ? { name: nameOrTargetOrConfig } : nameOrTargetOrConfig;\n nameOrTargetOrConfig.coerce = type;\n return bindable(nameOrTargetOrConfig);\n }\n /**\n * class MyClass {\n * @bindable.number num\n * }\n */\n return bindable({ coerce: type })(nameOrTargetOrConfig, key, descriptor);\n };\n}\n\nvar observableLogger = getLogger('aurelia-observable-decorator');\n/**\n * Internal flag to turn on / off auto pickup property type from metadata\n */\nvar _usePropertyType$1 = false;\nvar observable = function observable(nameOrTargetOrConfig, key, descriptor) {\n /**\n * @param target The class decorated\n * @param key The target class field of the decorator\n * @param descriptor class field descriptor\n * @param config user's config\n */\n function deco(target, key, descriptor, config) {\n // Used to check if we should pickup the type from metadata\n var coerce = config === undefined || typeof config === 'string' ? undefined : config.coerce;\n var propType;\n var coerceFunction;\n if (coerce) {\n switch (typeof coerce) {\n case 'string':\n coerceFunction = coerceFunctions[coerce];\n break;\n case 'function':\n coerceFunction = coerce;\n break;\n default: break;\n }\n if (coerceFunction === undefined) {\n observableLogger.warn(\"Invalid coerce instruction. Should be either one of \" + Object.keys(coerceFunctions) + \" or a function.\");\n }\n }\n else if (_usePropertyType$1) {\n propType = metadata.getOwn(metadata.propertyType, target, key);\n if (propType) {\n coerceFunction = coerceFunctions[coerceFunctionMap.get(propType)];\n if (coerceFunction === undefined) {\n observableLogger.warn(\"Unable to find coerce function for type \" + propType.name + \".\");\n }\n }\n }\n /**\n * class decorator?\n * @example\n * @observable('firstName') MyClass {}\n * @observable({ name: 'firstName' }) MyClass {}\n */\n var isClassDecorator = key === undefined;\n if (isClassDecorator) {\n target = target.prototype;\n key = typeof config === 'string' ? config : config.name;\n }\n // use a convention to compute the inner property name\n var innerPropertyName = \"_\" + key;\n var innerPropertyDescriptor = {\n configurable: true,\n enumerable: false,\n writable: true\n };\n if (config && 'defaultValue' in config) {\n var initValue = config.defaultValue;\n innerPropertyDescriptor.value = coerceFunction === undefined ? initValue : coerceFunction(initValue);\n }\n // determine callback name based on config or convention.\n var callbackName = (config && config.changeHandler) || key + \"Changed\";\n if (descriptor) {\n // babel passes in the property descriptor with a method to get the initial value.\n // set the initial value of the property if it is defined.\n // also make sure it's coerced\n if (typeof descriptor.initializer === 'function') {\n var initValue = descriptor.initializer();\n innerPropertyDescriptor.value = coerceFunction === undefined ? initValue : coerceFunction(initValue);\n }\n }\n else {\n // there is no descriptor if the target was a field in TS (although Babel provides one),\n // or if the decorator was applied to a class.\n descriptor = {};\n }\n // make the accessor enumerable by default, as fields are enumerable\n if (!('enumerable' in descriptor)) {\n descriptor.enumerable = true;\n }\n // we're adding a getter and setter which means the property descriptor\n // cannot have a \"value\" or \"writable\" attribute\n delete descriptor.value;\n delete descriptor.writable;\n delete descriptor.initializer;\n // Add the inner property on the prototype.\n Reflect.defineProperty(target, innerPropertyName, innerPropertyDescriptor);\n // add the getter and setter to the property descriptor.\n descriptor.get = function () { return this[innerPropertyName]; };\n descriptor.set = function (newValue) {\n var oldValue = this[innerPropertyName];\n var coercedValue = coerceFunction === undefined ? newValue : coerceFunction(newValue);\n if (coercedValue === oldValue) {\n return;\n }\n // Add the inner property on the instance and make it nonenumerable.\n this[innerPropertyName] = coercedValue;\n Reflect.defineProperty(this, innerPropertyName, { enumerable: false });\n if (this[callbackName]) {\n this[callbackName](coercedValue, oldValue, key);\n }\n };\n // make sure Aurelia doesn't use dirty-checking by declaring the property's\n // dependencies. This is the equivalent of \"@computedFrom(...)\".\n descriptor.get.dependencies = [innerPropertyName];\n if (isClassDecorator) {\n Reflect.defineProperty(target, key, descriptor);\n }\n else {\n return descriptor;\n }\n }\n /**\n * Decorating with parens\n * @example\n * @observable MyClass {} <----- this breaks, but will go into this condition\n * @observable('firstName') MyClass {}\n * @observable({ name: 'firstName' }) MyClass {}\n * class MyClass {\n * @observable() prop\n * }\n */\n if (key === undefined) {\n return function (t, k, d) { return deco(t, k, d, nameOrTargetOrConfig); };\n }\n /**\n * Decorating on class field\n * @example\n * class MyClass {\n * @observable prop\n * }\n */\n return deco(nameOrTargetOrConfig, key, descriptor);\n};\n['string', 'number', 'boolean', 'date'].forEach(createTypedObservable);\n/*\n | typescript | babel\n----------|------------------|-------------------------\nproperty | config | config\nw/parens | target, key | target, key, descriptor\n----------|------------------|-------------------------\nproperty | target, key | target, key, descriptor\nno parens | n/a | n/a\n----------|------------------|-------------------------\nclass | config | config\n | target | target\n*/\n/**\n * Toggle the flag for observable to auto pickup property type from metadata\n * The reason is sometimes we may want to use prop type on bindable, but not observable\n * and vice versa\n */\nfunction usePropertyType$1(shouldUsePropType) {\n _usePropertyType$1 = !!shouldUsePropType;\n}\n/**\n * Decorator: Creates a new observable decorator that can be used for fluent syntax purpose\n * @param type the type name that will be assign to observable decorator. `createTypedObservable('point') -> observable.point`\n */\nfunction createTypedObservable(type) {\n return observable[type] = function (nameOrTargetOrConfig, key, descriptor) {\n if (nameOrTargetOrConfig === undefined) {\n /**\n * MyClass {\n * @observable.number() num\n * }\n *\n * This will breaks so need to check for proper error\n * @observable.number()\n * class MyClass {}\n */\n return observable({ coerce: type });\n }\n if (key === undefined) {\n /**\n * @observable.number('num')\n * class MyClass {}\n *\n * @observable.number({...})\n * class MyClass\n *\n * class MyClass {\n * @observable.number({...})\n * num\n * }\n */\n nameOrTargetOrConfig = typeof nameOrTargetOrConfig === 'string' ? { name: nameOrTargetOrConfig } : nameOrTargetOrConfig;\n nameOrTargetOrConfig.coerce = type;\n return observable(nameOrTargetOrConfig);\n }\n /**\n * class MyClass {\n * @observable.number num\n * }\n */\n return observable({ coerce: type })(nameOrTargetOrConfig, key, descriptor);\n };\n}\n\nexport { bindable, usePropertyType as usePropertyTypeForBindable, createTypedBindable, observable, usePropertyType$1 as usePropertyTypeForObservable, createTypedObservable, coerceFunctions, coerceFunctionMap, mapCoerceFunction };\n"],"sourceRoot":""}