server.get('https://api.github.com/repos/emberjs/ember.js/releases', function(/*db, request*/) { let version = Ember.copy(EmberVersionsResponse[0]); version['published_at'] = window.moment().subtract(14, 'weeks'); version['name'] = 'Ember v15.0.0'; let olderVersion = Ember.copy(EmberVersionsResponse[1]); olderVersion['published_at'] = window.moment().subtract(5, 'months'); olderVersion['name'] = 'Ember v14.0.0'; return [version, olderVersion]; });
return run(() => { this.assignment_group = Ember.copy(fixtures.assignment_groups, true).findBy('id', '1') this.student = Ember.Object.create(Ember.copy(groupScores)) return this.component.setProperties({ student: this.student, subtotal: { name: this.assignment_group.name, weight: this.assignment_group.group_weight, key: `assignment_group_${this.assignment_group.id}` } }) })
return db.remove(hash).then(function(response){ var rhash = Ember.copy(hash, true); rhash.rev = response.rev; rhash.id = pouchIdToId(rhash._id); delete rhash._id; return self.syncRelationships(store, type, rhash, hash, "delete"); }, function(a){
return db.put(hash).then(function(response){ var rhash = Ember.copy(hash, true); rhash.rev = response.rev; rhash.id = pouchIdToId(hash._id); delete rhash._id; return self.syncRelationships(store, type, rhash, oldHash, "update"); });
test('should add a series', function(assert) { assert.expect(2); this.cityData = cityData; this.lineChartOptions = lineChartOptions; this.render(hbs` {{high-charts content=cityData chartOptions=lineChartOptions}} `); assert.equal(this.$('.highcharts-legend .highcharts-legend-item').length, 3, 'base series count'); // add a series to chart content let cityDataCopy = Ember.copy(cityData, true); cityDataCopy.push({ name: 'San Fransico', data: [ [1, 7.0], [2, 9.5], [3, 9.5] ] }); this.set('cityData', cityDataCopy); assert.equal(this.$('.highcharts-legend .highcharts-legend-item').length, 4, 'new series count'); });
list.forEach(function(element) { // Don't modify the original object. element = Ember.copy(element); var name = element['name']; delete element['name']; dict[name] = element; });
setup: function(){ var a; initialize(this.container); if (typeof(attrs) === 'function') { a = attrs.apply(this); } else { a = Ember.copy(attrs, true); } if (a.template) { a.template = Ember.Handlebars.compile(a.template); } a.container = this.container; if (a.context && !(a.context instanceof Ember.Object) ) { a.context = Ember.Object.create(a.context); } if (a.setup) { a.setup.apply(this); delete a.setup; } view = Ember.View.create(a); run(function() { view.appendTo('#qunit-fixture'); }); },
let evaluation = this.get('poll.options').map((option) => { return { answers: Ember.copy(answers), option, score: 0 }; });
env.adapter.ajax = function(url, verb, hash) { passedUrl = url; passedVerb = verb; passedHash = hash; return run(Ember.RSVP, 'resolve', Ember.copy(value, true)); };
style: function(feature) { let s = Ember.copy(defaultStyle); s.fillColor = `#0${feature.id}`; s.color = s.fillColor; return s; }
return Ember.run(() => { store.push({ data: { type: 'person', id: 1, attributes: data } }); var payload = { person: Ember.copy(data, true) }; payload.person.id = 1; payload.person.name.first = 'Bran'; payload.person.addresses[0].street = '1 Broken Tower'; server.get('/people/1', function() { return [ 200, {"Content-Type": "application/json"}, JSON.stringify(payload) ]; }); return store.find('person', 1).then(function(person) { // Access values that will change to prime CP cache person.get('name.first'); person.get('addresses.firstObject.street'); return person.reload(); }).then(function(person) { var name = person.get('name'); var addresses = person.get('addresses'); assert.equal(name.get('first'), 'Bran', "fragment correctly updated"); assert.equal(addresses.get('firstObject.street'), '1 Broken Tower', "fragment array fragment correctly updated"); }); });
return Ember.run(() => { store.push({ data: { type: 'person', id: 1, attributes: data } }); var payload = { person: Ember.copy(data, true) }; payload.person.id = 1; payload.person.name.first = 'Ned'; payload.person.addresses[0].street = '1 Godswood'; server.put('/people/1', function() { return [ 200, {"Content-Type": "application/json"}, JSON.stringify(payload) ]; }); return store.find('person', 1).then(function(person) { return person.save(); }).then(function(person) { var name = person.get('name'); var addresses = person.get('addresses'); assert.ok(!name.get('hasDirtyAttributes'), "fragment is clean"); assert.ok(!addresses.isAny('hasDirtyAttributes'), "all fragment array fragments are clean"); assert.ok(!addresses.get('hasDirtyAttributes'), "fragment array is clean"); assert.ok(!person.get('hasDirtyAttributes'), "owner record is clean"); assert.equal(name.get('first'), 'Ned', "fragment correctly updated"); assert.equal(addresses.get('firstObject.street'), '1 Godswood', "fragment array fragment correctly updated"); }); });
findMany: function (store, type, ids, opts) { var namespace = this._namespaceForType(type); var allowRecursive = true, results = Ember.A([]), record; /** * In the case where there are relationships, this method is called again * for each relation. Given the relations have references to the main * object, we use allowRecursive to avoid going further into infinite * recursiveness. * * Concept from ember-indexdb-adapter */ if (opts && typeof opts.allowRecursive !== 'undefined') { allowRecursive = opts.allowRecursive; } for (var i = 0; i < ids.length; i++) { record = namespace.records[ids[i]]; if (!record || !record.hasOwnProperty('id')) { return Ember.RSVP.reject(new Error("Couldn't find record of type '" + type.modelName + "' for the id '" + ids[i] + "'.")); } results.push(Ember.copy(record)); } if (results.get('length') && allowRecursive) { return this.loadRelationshipsForMany(store, type, results); } else { return Ember.RSVP.resolve(results); } },
return promise.then(function(adapterPayload){ var payload = serializer.extract(store, type, adapterPayload, null, 'findHasMany'); var records = store.pushMany(type, payload); hasMany.set('meta', Ember.copy(store.metadataFor(type))); hasMany.addObjects(records); return hasMany; });
normalizeResponse: function(store, primaryModelClass, payload, id, requestType) { // If the response is empty, return the appropriate JSON API response. // Unfortunately, this._super apparently doesn't support this condition properly. // Based on the documentation at: http://jsonapi.org/format/ if(payload === null) { return { data: null }; } let payloadWithRoot = {}, isCollection = payload.length > 0, key = isCollection ? Ember.Inflector.inflector.pluralize(primaryModelClass.modelName) : primaryModelClass.modelName; payloadWithRoot[key] = payload; if(isCollection) { payload.forEach((item) => { this._mapRecord(item); this._extractRelationships(store, payloadWithRoot, item, primaryModelClass); item.attributes = Ember.copy(item, true); if(item.type) { item.type = primaryModelClass.modelName; } delete item.attributes.id; }); } else { this._mapRecord(payload); this._extractRelationships(store, payloadWithRoot, payload, primaryModelClass); payload.attributes = Ember.copy(payload, true); if(payload.type) { payload.type = primaryModelClass.modelName; } delete payload.attributes.id; } return this._super(store, primaryModelClass, payloadWithRoot, id, requestType); },
// This helper is internal to liquid-with. export default function withApplyHelper(options){ var view = options.data.view, parent = view.get('liquidWithParent'), withArgs = parent.get('originalArgs').slice(); withArgs[0] = 'lwith-view.boundContext'; options = Ember.copy(options); // This works to inject our keyword in Ember >= 1.9 if (!view._keywords) { view._keywords = {}; } view._keywords['lwith-view'] = view; // This works to inject our keyword in Ember < 1.9 if (!options.data.keywords) { options.data.keywords = {}; } options.data.keywords['lwith-view'] = view; options.fn = parent.get('innerTemplate'); options.hash = parent.get('originalHash'); options.hashTypes = parent.get('originalHashTypes'); withArgs.push(options); return Ember.Handlebars.helpers.with.apply(this, withArgs); }
[ADD_HOOK]: ({env, options, payload}, isEditing=false) => { let cardId = Ember.uuid(); let cardName = env.name; if (isEditing) { cardName = cardName + EDITOR_CARD_SUFFIX; } let destinationElementId = `mobiledoc-editor-card-${cardId}`; let element = document.createElement('div'); element.id = destinationElementId; // The data must be copied to avoid sharing the reference payload = Ember.copy(payload, true); let card = Ember.Object.create({ destinationElementId, cardName, payload, callbacks: env, editor, postModel: env.postModel }); Ember.run.schedule('afterRender', () => { this.get('componentCards').pushObject(card); }); return { card, element }; },
function explodePiece(context, piece) { var childContext = Ember.copy(context); var selectors = [piece.pick, piece.pick]; var cleanupOld, cleanupNew; if (piece.pickOld) { selectors[0] = piece.pickOld; } if (piece.pickNew) { selectors[1] = piece.pickNew; } if (selectors[0]) { cleanupOld = _explodePart(context, 'oldElement', childContext, selectors[0]); } if (selectors[1]) { cleanupNew = _explodePart(context, 'newElement', childContext, selectors[1]); } // if we were trying to target specific selectors and didn't find // any matches, there's no transition to run (if there were no // selectors, we deliberately fall through an animate the underlying // "background" elements). if (!cleanupOld && !cleanupNew && (selectors[0] || selectors[1])) { return Promise.resolve(); } return new Promise((resolve, reject) => { animationFor(context, piece).apply(childContext).then(resolve, reject); }).finally(() => { if (cleanupOld) { cleanupOld(); } if (cleanupNew) { cleanupNew(); } }); }
function withLockedModel(outletState) { var r, c; if (outletState && (r = outletState.render) && (c = r.controller) && !outletState._lf_model) { outletState = Ember.copy(outletState); outletState._lf_model = c.get('model'); } return outletState; }
setupController: function (controller, model) { // Call _super for default behavior this._super(controller, model); // Implement your custom setup after let filteredPokemons = Ember.copy(model); controller.set('filteredPokemons', filteredPokemons); controller.set("disableLoadMore", true); }
model: function() { // operate on a copy so we don't mess up the original object var invoice = Ember.copy(this.get('invoice'), true); invoice.setProperties({ isNew: false, }); return invoice; }.property("invoice"),
currentUser: function () { var payload = this.get('content.user'); if(payload){ return this.container.lookup('store:main').push('user', Ember.copy(payload)); }else{ return null; } }.property('content')
return this.get('contentList').map(function(item) { var clonedItem = Ember.copy(item); if (clonedItem.group === lastGroup) { clonedItem.group = null; } else { lastGroup = clonedItem.group; } return clonedItem; });
payload.forEach((item) => { this._mapRecord(item); this._extractRelationships(store, payloadWithRoot, item, primaryModelClass); item.attributes = Ember.copy(item, true); if(item.type) { item.type = primaryModelClass.modelName; } delete item.attributes.id; });
findAll: function (store, type) { var namespace = this._namespaceForType(type), results = Ember.A([]); for (var id in namespace.records) { results.push(Ember.copy(namespace.records[id])); } return Ember.RSVP.resolve(results); },
return new Ember.RSVP.Promise(function(resolve) { var value = Ember.copy(callback.call(context), true); if (get(adapter, 'simulateRemoteResponse')) { // Schedule with setTimeout Ember.run.later(null, resolve, value, get(adapter, 'latency')); } else { // Asynchronous, but at the of the runloop with zero latency resolve(value); } }, 'DS: FixtureAdapter#simulateRemoteCall');
const mergeDefaults = function (defaults, options) { const unsetKeys = Ember.A(keys(defaults)).removeObjects(keys(options)); const settings = Ember.copy(options, true); for (let i = 0, len = unsetKeys.length; i < len; i++) { let key = unsetKeys[i]; settings[key] = defaults[key]; } return settings; };
_query: function (records, query) { var results = Ember.A([]), record; for (var id in records) { record = records[id]; if (!query || this._evaluate(record, query)) { results.push(Ember.copy(record)); } } return results; },
/** Returns all changed attributes and their old and new values. Example ```javascript // store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' }); postModel.set('title', 'Ember.js rocks!'); postSnapshot.changedAttributes(); // => { title: ['Ember.js rocks', 'Ember.js rocks!'] } ``` @method changedAttributes @return {Object} All changed attributes of the current snapshot */ changedAttributes() { let changedAttributes = new EmptyObject(); let changedAttributeKeys = Object.keys(this._changedAttributes); for (let i=0, length = changedAttributeKeys.length; i < length; i++) { let key = changedAttributeKeys[i]; changedAttributes[key] = Ember.copy(this._changedAttributes[key]); } return changedAttributes; }
return run(() => { this.student = Ember.Object.create(Ember.copy(periodScores)) return this.component.setProperties({ student: this.student, subtotal: { name: 'Grading Period 1', weight: 0.65, key: 'grading_period_1' } }) })