export function deprecatingAlias(dependentKey, options) { return computed(dependentKey, { get(key) { deprecate(`Usage of \`${key}\` is deprecated, use \`${dependentKey}\` instead.`, false, options); return get(this, dependentKey); }, set(key, value) { deprecate(`Usage of \`${key}\` is deprecated, use \`${dependentKey}\` instead.`, false, options); set(this, dependentKey, value); return value; } }); }
export function addListener(obj, eventName, target, method, once) { assert('You must pass at least an object and event name to Ember.addListener', !!obj && !!eventName); deprecate( `didInitAttrs called in ${obj && obj.toString && obj.toString()}.`, eventName !== 'didInitAttrs', { id: 'ember-views.did-init-attrs', until: '3.0.0', url: 'https://emberjs.com/deprecations/v2.x#toc_ember-component-didinitattrs' } ); if (!method && 'function' === typeof target) { method = target; target = null; } let flags = 0; if (once) { flags |= ONCE; } metaFor(obj).addToListeners(eventName, target, method, flags); if ('function' === typeof obj.didAddListener) { obj.didAddListener(eventName, target, method); } }
export function observer(...args) { let func = args.slice(-1)[0]; let paths; let addWatchedProperty = path => { paths.push(path); }; let _paths = args.slice(0, -1); if (typeof func !== 'function') { // revert to old, soft-deprecated argument ordering deprecate('Passing the dependentKeys after the callback function in Ember.observer is deprecated. Ensure the callback function is the last argument.', false, { id: 'ember-metal.observer-argument-order', until: '3.0.0' }); func = args[0]; _paths = args.slice(1); } paths = []; for (let i = 0; i < _paths.length; ++i) { expandProperties(_paths[i], addWatchedProperty); } if (typeof func !== 'function') { throw new EmberError('Ember.observer called without a function'); } func.__ember_observes__ = paths; return func; }
function processHash(b, node, moduleName) { for (let i = 0; i < node.hash.pairs.length; i++) { let pair = node.hash.pairs[i]; let { key, value } = pair; let sourceInformation = calculateLocationDisplay(moduleName, pair.loc); if (key === 'classBinding') { return; } assert(`Setting 'attributeBindings' via template helpers is not allowed ${sourceInformation}`, key !== 'attributeBindings'); if (key.substr(-7) === 'Binding') { let newKey = key.slice(0, -7); deprecate( `You're using legacy binding syntax: ${key}=${exprToString(value)} ${sourceInformation}. Please replace with ${newKey}=${value.original}`, false, { id: 'ember-template-compiler.transform-old-binding-syntax', until: '3.0.0' } ); pair.key = newKey; if (value.type === 'StringLiteral') { pair.value = b.path(value.original); } } } }
function deprecateResolverFunction(registry) { deprecate('Passing a `resolver` function into a Registry is deprecated. Please pass in a Resolver object with a `resolve` method.', false, { id: 'ember-application.registry-resolver-as-function', until: '3.0.0', url: 'https://emberjs.com/deprecations/v2.x#toc_registry-resolver-as-function' }); registry.resolver = { resolve: registry.resolver }; }
function fmt(str, formats) { deprecate( 'Ember.String.fmt is deprecated, use ES6 template strings instead.', false, { id: 'ember-string-utils.fmt', until: '3.0.0', url: 'http://babeljs.io/docs/learn-es2015/#template-strings' } ); return _fmt(...arguments); }
export function required() { deprecate( 'Ember.required is deprecated as its behavior is inconsistent and unreliable.', false, { id: 'ember-metal.required', until: '3.0.0' } ); return REQUIRED; }
function deprecateResolverFunction(registry) { deprecate( missingResolverFunctionsDeprecation, false, { id: 'ember-application.registry-resolver-as-function', until: '3.0.0', url: 'https://emberjs.com/deprecations/v2.x#toc_registry-resolver-as-function' } ); registry.resolver = { resolve: registry.resolver }; }
'@each': computed(function() { deprecate(`Getting the '@each' property on object ${toString(this)} is deprecated`, false, { id: 'ember-metal.getting-each', until: '3.5.0', url: 'https://emberjs.com/deprecations/v3.x#toc_getting-the-each-property', }); return eachProxyFor(this); }).readOnly(),
node.params.forEach(param => { if (param.type !== 'PathExpression') { return; } deprecate(deprecationMessage(moduleName, node, param), false, { id: 'ember-template-compiler.deprecate-render-model', until: '3.0.0', url: 'https://emberjs.com/deprecations/v2.x#toc_model-param-in-code-render-code-helper' }); });
walker.visit(ast, function(node) { if (pluginContext.validate(node)) { let action = hashPairForKey(node.hash, 'action'); let on = hashPairForKey(node.hash, 'on'); let onEvent = hashPairForKey(node.hash, 'onEvent'); let normalizedOn = on || onEvent; let moduleInfo = calculateLocationDisplay(moduleName, node.loc); if (normalizedOn && normalizedOn.value.type !== 'StringLiteral') { deprecate( `Using a dynamic value for '#{normalizedOn.key}=' with the '{{input}}' helper ${moduleInfo}is deprecated.`, false, { id: 'ember-template-compiler.transform-input-on-to-onEvent.dynamic-value', until: '3.0.0' } ); normalizedOn.key = 'onEvent'; return; // exit early, as we cannot transform further } removeFromHash(node.hash, normalizedOn); removeFromHash(node.hash, action); if (!action) { deprecate( `Using '{{input ${normalizedOn.key}="${normalizedOn.value.value}" ...}}' without specifying an action ${moduleInfo}will do nothing.`, false, { id: 'ember-template-compiler.transform-input-on-to-onEvent.no-action', until: '3.0.0' } ); return; // exit early, if no action was available there is nothing to do } let specifiedOn = normalizedOn ? `${normalizedOn.key}="${normalizedOn.value.value}" ` : ''; if (normalizedOn && normalizedOn.value.value === 'keyPress') { // using `keyPress` in the root of the component will // clobber the keyPress event handler normalizedOn.value.value = 'key-press'; } let expected = `${normalizedOn ? normalizedOn.value.value : 'enter'}="${action.value.original}"`; deprecate( `Using '{{input ${specifiedOn}action="${action.value.original}"}}' ${moduleInfo}is deprecated. Please use '{{input ${expected}}}' instead.`, false, { id: 'ember-template-compiler.transform-input-on-to-onEvent.normalized-on', until: '3.0.0' } ); if (!normalizedOn) { normalizedOn = b.pair('onEvent', b.string('enter')); } node.hash.pairs.push(b.pair( normalizedOn.value.value, action.value )); } });
resource(name, options = {}, callback) { if (arguments.length === 2 && typeof options === 'function') { callback = options; options = {}; } options.resetNamespace = true; deprecate('this.resource() is deprecated. Use this.route(\'name\', { resetNamespace: true }, function () {}) instead.', false, { id: 'ember-routing.router-resource', until: '3.0.0' }); this.route(name, options, callback); }
// .......................................................... // PROPERTY CHANGES // /** @method propertyWillChange @for Ember @private */ function propertyWillChange() { deprecate( `'propertyWillChange' is deprecated and has no effect. It is safe to remove this call.`, false, { id: 'ember-metal.deprecate-propertyWillChange', until: '3.5.0', url: 'https://emberjs.com/deprecations/v3.x/#toc_use-notifypropertychange-instead-of-propertywillchange-and-propertydidchange' } ); }
return function() { deprecate( `Using \`${typeForMessage}.registry.${deprecatedProperty}\` is deprecated. Please use \`${typeForMessage}.${nonDeprecatedProperty}\` instead.`, false, { id: 'ember-application.app-instance-registry', until: '3.0.0', url: 'https://emberjs.com/deprecations/v2.x/#toc_ember-application-registry-ember-applicationinstance-registry' } ); return instance[nonDeprecatedProperty](...arguments); };
export function scheduleOnce(queue /*, target, method*/) { assert( `You have turned on testing mode, which disabled the run-loop's autorun. ` + `You will need to wrap any code with asynchronous side-effects in a run`, currentRunLoop || !isTesting() ); deprecate(`Scheduling into the '${queue}' run loop queue is deprecated.`, queue !== 'sync', { id: 'ember-metal.run.sync', until: '3.5.0', }); return backburner.scheduleOnce(...arguments); }
/** @method propertyDidChange @for Ember @private */ function propertyDidChange(obj, keyName, _meta) { deprecate( `'propertyDidChange' is deprecated in favor of 'notifyPropertyChange'. It is safe to change this call to 'notifyPropertyChange'.`, false, { id: 'ember-metal.deprecate-propertyDidChange', until: '3.5.0', url: 'https://emberjs.com/deprecations/v3.x/#toc_use-notifypropertychange-instead-of-propertywillchange-and-propertydidchange' } ); notifyPropertyChange(obj, keyName, _meta); }
export function _immediateObserver() { deprecate('Usage of `Ember.immediateObserver` is deprecated, use `Ember.observer` instead.', false, { id: 'ember-metal.immediate-observer', until: '3.0.0' }); for (let i = 0; i < arguments.length; i++) { let arg = arguments[i]; assert( 'Immediate observers must observe internal properties only, not properties on other objects.', typeof arg !== 'string' || arg.indexOf('.') === -1 ); } return observer.apply(this, arguments); }
export function getSafeString() { deprecate( 'Ember.Handlebars.SafeString is deprecated in favor of Ember.String.htmlSafe', false, { id: 'ember-htmlbars.ember-handlebars-safestring', until: '3.0.0', url: 'https://emberjs.com/deprecations/v2.x#toc_use-ember-string-htmlsafe-over-ember-handlebars-safestring' } ); return SafeString; }
this._runInitializer('initializers', (name, initializer) => { assert(`No application initializer named '${name}'`, !!initializer); if (initializer.initialize.length === 2) { deprecate(`The \`initialize\` method for Application initializer '${name}' should take only one argument - \`App\`, an instance of an \`Application\`.`, false, { id: 'ember-application.app-initializer-initialize-arguments', until: '3.0.0', url: 'https://emberjs.com/deprecations/v2.x/#toc_initializer-arity' }); initializer.initialize(this.__registry__, this); } else { initializer.initialize(this); } });
Ember.Backburner = function() { deprecate( 'Usage of Ember.Backburner is deprecated.', false, { id: 'ember-metal.ember-backburner', until: '2.8.0', url: 'http://emberjs.com/deprecations/v2.x/#toc_ember-backburner' } ); function BackburnerAlias(args) { return Backburner.apply(this, args); } BackburnerAlias.prototype = Backburner.prototype; return new BackburnerAlias(arguments); };
function appendLiveRoute(liveRoutes, defaultParentState, renderOptions) { let target; let myState = { render: renderOptions, outlets: Object.create(null), wasUsed: false }; if (renderOptions.into) { target = findLiveRoute(liveRoutes, renderOptions.into); } else { target = defaultParentState; } if (target) { set(target.outlets, renderOptions.outlet, myState); } else { if (renderOptions.into) { deprecate( `Rendering into a {{render}} helper that resolves to an {{outlet}} is deprecated.`, false, { id: 'ember-routing.top-level-render-helper', until: '3.0.0', url: 'https://emberjs.com/deprecations/v2.x/#toc_rendering-into-a-render-helper-that-resolves-to-an-outlet' } ); // Megahax time. Post-3.0-breaking-changes, we will just assert // right here that the user tried to target a nonexistent // thing. But for now we still need to support the `render` // helper, and people are allowed to target templates rendered // by the render helper. So instead we defer doing anyting with // these orphan renders until afterRender. appendOrphan(liveRoutes, renderOptions.into, myState); } else { liveRoutes = myState; } } return { liveRoutes, ownState: myState }; }
let arr = ['a', 'b', 'c']; arr.contains('a'); // true arr.contains('z'); // false ``` @method contains @deprecated Use `Enumerable#includes` instead. See https://emberjs.com/deprecations/v2.x#toc_enumerable-contains @param {Object} obj The object to search for. @return {Boolean} `true` if object is found in enumerable. @public */ contains(obj) { deprecate( '`Enumerable#contains` is deprecated, use `Enumerable#includes` instead.', false, { id: 'ember-runtime.enumerable-contains', until: '3.0.0', url: 'https://emberjs.com/deprecations/v2.x#toc_enumerable-contains' } ); let found = this.find(item => item === obj); return found !== undefined; }, /** Iterates through the enumerable, calling the passed function on each item. This method corresponds to the `forEach()` method defined in JavaScript 1.6. The callback method you provide should have the following signature (all parameters are optional):
export function get(obj, keyName) { assert(`Get must be called with two arguments; an object and a property key`, arguments.length === 2); assert(`Cannot call get with '${keyName}' on an undefined object.`, obj !== undefined && obj !== null); assert(`The key provided to get must be a string or number, you passed ${keyName}`, typeof keyName === 'string' || (typeof keyName === 'number' && !isNaN(keyName))); assert(`'this' in paths is not supported`, typeof keyName !== 'string' || keyName.lastIndexOf('this.', 0) !== 0); assert('Cannot call `get` with an empty string', keyName !== ''); let type = typeof obj; let isObject = type === 'object'; let isFunction = type === 'function'; let isObjectLike = isObject || isFunction; let descriptor = undefined; let value; if (isObjectLike) { if (EMBER_METAL_TRACKED_PROPERTIES) { let tracker = getCurrentTracker(); if (tracker) tracker.add(tagForProperty(obj, keyName)); } if (EMBER_METAL_ES5_GETTERS) { descriptor = descriptorFor(obj, keyName); } if (!EMBER_METAL_ES5_GETTERS || descriptor === undefined) { value = getPossibleMandatoryProxyValue(obj, keyName); if (DESCRIPTOR_TRAP && isDescriptorTrap(value)) { descriptor = value[DESCRIPTOR]; } else if (isDescriptor(value)) { deprecate( `[DEPRECATED] computed property '${keyName}' was not set on object '${obj && obj.toString && obj.toString()}' via 'defineProperty'`, !EMBER_METAL_ES5_GETTERS, { id: 'ember-meta.descriptor-on-object', until: '3.5.0', url: 'https://emberjs.com/deprecations/v3.x#toc_use-defineProperty-to-define-computed-properties' } ); descriptor = value; } } if (descriptor !== undefined) { return descriptor.get(obj, keyName); } } else { value = obj[keyName]; } if (isPath(keyName)) { return _getPath(obj, keyName); } else if (value === undefined && isObject && !(keyName in obj) && typeof obj.unknownProperty === 'function') { return obj.unknownProperty(keyName); } else { return value; } }
Object.defineProperty(Ember, 'LOG_VERSION', { get() { return ENV.LOG_VERSION; }, set(value) { ENV.LOG_VERSION = !!value; }, enumerable: false }); if (DEBUG) { Object.defineProperty(Ember, 'MODEL_FACTORY_INJECTIONS', { get() { return false; }, set(value) { deprecate( 'Ember.MODEL_FACTORY_INJECTIONS is no longer required', false, { id: 'ember-metal.model_factory_injections', until: '2.17.0', url: 'https://emberjs.com/deprecations/v2.x/#toc_id-ember-metal-model_factory_injections' } ); }, enumerable: false }); } Object.defineProperty(Ember, 'LOG_BINDINGS', { get() { return ENV.LOG_BINDINGS; }, set(value) { ENV.LOG_BINDINGS = !!value; }, enumerable: false });
_addBeforeObserver(this, contentKey, null, contentPropertyWillChange); addObserver(this, contentKey, null, contentPropertyDidChange); }, didUnwatchProperty(key) { let contentKey = `content.${key}`; _removeBeforeObserver(this, contentKey, null, contentPropertyWillChange); removeObserver(this, contentKey, null, contentPropertyDidChange); }, unknownProperty(key) { let content = get(this, 'content'); if (content) { deprecate( `You attempted to access \`${key}\` from \`${this}\`, but object proxying is deprecated. Please use \`model.${key}\` instead.`, !this.isController, { id: 'ember-runtime.controller-proxy', until: '3.0.0' } ); return get(content, key); } }, setUnknownProperty(key, value) { let m = meta(this); if (m.proto === this) { // if marked as prototype then just defineProperty // rather than delegate defineProperty(this, key, null, value); return value; }
/** If the object implements `Ember.Freezable`, then this will return a new copy if the object is not frozen and the receiver if the object is frozen. Raises an exception if you try to call this method on a object that does not support freezing. You should use this method whenever you want a copy of a freezable object since a freezable object can simply return itself without actually consuming more memory. @method frozenCopy @return {Object} copy of receiver or receiver @deprecated Use `Object.freeze` instead. @private */ frozenCopy() { deprecate( '`frozenCopy` is deprecated, use `Object.freeze` instead.', false, { id: 'ember-runtime.frozen-copy', until: '3.0.0' } ); if (Freezable && Freezable.detect(this)) { return get(this, 'isFrozen') ? this : this.copy().freeze(); } else { throw new EmberError(`${this} does not support freezing`); } } });
/** An empty function useful for some operations. Always returns `this`. @method K @return {Object} @public */ function deprecatedEmberK() { return this; } Object.defineProperty(Ember, 'K', { get() { deprecate( 'Ember.K is deprecated in favor of defining a function inline.', false, { id: 'ember-metal.ember-k', until: '3.0.0', url: 'http://emberjs.com/deprecations/v2.x#toc_code-ember-k-code' } ); return deprecatedEmberK; } }); Object.defineProperty(Ember, 'testing', { get: EmberDebug.isTesting, set: EmberDebug.setTesting, enumerable: false });
} return true; }), _getModels(params) { let modelCount = params.length - 1; let models = new Array(modelCount); for (let i = 0; i < modelCount; i++) { let value = params[i + 1]; while (ControllerMixin.detect(value)) { deprecate( 'Providing `{{link-to}}` with a param that is wrapped in a controller is deprecated. ' + (this.parentView ? 'Please update `' + this.parentView + '` to use `{{link-to "post" someController.model}}` instead.' : ''), false, { id: 'ember-routing-views.controller-wrapped-param', until: '3.0.0' } ); value = value.get('model'); } models[i] = value; } return models; }, /** The default href value to use while a link-to is loading. Only applies when tagName is 'a'
// tslint:disable-next-line:max-line-length assert(`You cannot use a computed property for the component's \`elementId\` (${this}).`, descriptorFor(this, 'elementId') === undefined); // tslint:disable-next-line:max-line-length assert(`You cannot use a computed property for the component's \`tagName\` (${this}).`, descriptorFor(this, 'tagName') === undefined); if (!this.elementId && this.tagName !== '') { this.elementId = guidFor(this); } if (environment._ENABLE_DID_INIT_ATTRS_SUPPORT) { deprecate( `[DEPRECATED] didInitAttrs called in ${this.toString()}.`, typeof(this.didInitAttrs) !== 'function', { id: 'ember-views.did-init-attrs', until: '3.0.0', url: 'https://emberjs.com/deprecations/v2.x#toc_ember-component-didinitattrs' } ); } else { assert(`didInitAttrs called in ${this.toString()} is no longer supported.`, typeof(this.didInitAttrs) !== 'function'); } assert( 'Using a custom `.render` function is no longer supported.', !this.render ); }, __defineNonEnumerable(property) {