Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getTarget(instance) {
// TODO: Deprecate specifying `targetObject`
let target = get(instance, 'targetObject');
// if a `targetObject` CP was provided, use it
if (target) { return target; }
// if _targetObject use it
if (instance._targetObject) { return instance._targetObject; }
target = get(instance, 'target');
if (target) {
if (typeof target === 'string') {
let value = get(instance, target);
if (value === undefined) {
value = get(context.lookup, target);
}
return value;
} else {
return target;
}
}
return null;
}
replace(idx, amt, objects) {
assert('The third argument to replace needs to be an array.', objects === null || objects === undefined || Array.isArray(objects));
// if we replaced exactly the same number of items, then pass only the
// replaced range. Otherwise, pass the full remaining array length
// since everything has shifted
let len = objects ? get(objects, 'length') : 0;
arrayContentWillChange(this, idx, amt, len);
if (len === 0) {
this.splice(idx, amt);
} else {
replace(this, idx, amt, objects);
}
arrayContentDidChange(this, idx, amt, len);
return this;
},
export function removeAt(array, start, len) {
if ('number' === typeof start) {
if ((start < 0) || (start >= get(array, 'length'))) {
throw new EmberError(OUT_OF_RANGE_EXCEPTION);
}
// fast case
if (len === undefined) {
len = 1;
}
array.replace(start, len, EMPTY);
}
return array;
}
knownForType(type) {
let namespace = get(this, 'namespace');
let suffix = StringUtils.classify(type);
let typeRegexp = new RegExp(`${suffix}$`);
let known = dictionary(null);
let knownKeys = Object.keys(namespace);
for (let index = 0; index < knownKeys.length; index++) {
let name = knownKeys[index];
if (typeRegexp.test(name)) {
let containerName = this.translateToContainerFullname(type, name);
known[containerName] = true;
}
}
return known;
templateFor(component, env) {
let Template = get(component, 'layout');
let owner = component[OWNER];
if (Template) {
return env.getTemplate(Template, owner);
}
let layoutName = get(component, 'layoutName');
if (layoutName) {
let template = owner.lookup('template:' + layoutName);
if (template) {
return template;
}
}
return owner.lookup(DEFAULT_LAYOUT);
}
triggerAction(opts = {}) {
let { action, target, actionContext } = opts;
action = action || get(this, 'action');
target = target || getTarget(this);
if (actionContext === undefined) {
actionContext = get(this, 'actionContextObject') || this;
}
if (target && action) {
let ret;
if (target.send) {
ret = target.send(...[action].concat(actionContext));
} else {
assert(`The action '${action}' did not exist on ${target}`, typeof target[action] === 'function');
ret = target[action](...[].concat(actionContext));
}
if (ret !== false) {
return true;
}
}
lastObject: computed(function() {
return objectAt(this, get(this, 'length') - 1);
}).readOnly(),
pushObject(obj) {
this.insertAt(get(this, 'length'), obj);
return obj;
},
lastIndexOf(object, startAt) {
let len = get(this, 'length');
if (startAt === undefined || startAt >= len) {
startAt = len - 1;
}
if (startAt < 0) {
startAt += len;
}
for (let idx = startAt; idx >= 0; idx--) {
if (objectAt(this, idx) === object) {
return idx;
}
}
return -1;
hasRoute(routeName) {
return get(this, 'router').hasRoute(routeName);
},