Skip to content

Instantly share code, notes, and snippets.

@e00dan
Last active January 31, 2016 15:06
Show Gist options
  • Save e00dan/15abfa383febdc0a10ba to your computer and use it in GitHub Desktop.
Save e00dan/15abfa383febdc0a10ba to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
addUser() {
this.store.createRecord('user', { name: 'Added user', date: new Date() });
}
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.peekAll('user');
},
afterModel() {
this.store.createRecord('user', { name: 'Test 1' });
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{#each model as |user|}}
{{user.name}}<br/>
{{/each}}
<hr/>
<button {{action 'addUser'}}>Add user</button>
<br>
<br>
export function initialize(application) {
DS.RecordArray.reopen({
addInternalModel(internalModel, idx) {
var content = Ember.get(this, 'content');
if (idx === undefined) {
content.addObject(internalModel);
} else if (!content.contains(internalModel)) {
content.insertAt(idx, internalModel);
}
}
});
DS.RecordArrayManager.reopen({
recordWasLoaded(record) {
var typeClass = record.type;
var recordArrays = this.filteredRecordArrays.get(typeClass);
var filter;
recordArrays.forEach((array) => {
filter = get(array, 'filterFunction');
this.updateFilterRecordArray(array, filter, typeClass, record);
});
if (this.liveRecordArrays.has(typeClass)) {
var liveRecordArray = this.liveRecordArrays.get(typeClass);
this._addRecordToRecordArray(liveRecordArray, record);
}
},
_addRecordToRecordArray(array, record) {
console.log('test');
var recordArrays = this.recordArraysForRecord(record);
if (!recordArrays.has(array)) {
array.addInternalModel(record, 0);
//recordArrays.add(array);
}
},
});
DS.Store.reopen({
createRecordAtBeginning() {
},
buildInternalModel(type, id, data) {
console.log('build internal model');
var typeMap = this.typeMapFor(type);
var idToRecord = typeMap.idToRecord;
Ember.assert(`The id ${id} has already been used with another record of type ${type.toString()}.`, !id || !idToRecord[id]);
Ember.assert(`'${Ember.inspect(type)}' does not appear to be an ember-data model`, (typeof type._create === 'function') );
// lookupFactory should really return an object that creates
// instances with the injections applied
var internalModel = new DS.InternalModel(type, id, this, null, data);
// if we're creating an item, this process will be done
// later, once the object has been persisted.
if (id) {
idToRecord[id] = internalModel;
}
console.log(typeMap.records);
typeMap.records.push(internalModel);
return internalModel;
},
});
};
export default {
name: 'reopen store',
after: 'store',
initialize: initialize
};
import DS from 'ember-data';
export default DS.Model.extend({
});
{
"version": "0.5.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.2.0/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment