Last active
March 13, 2025 07:15
-
-
Save ankushdharkar/64352849c2b484330c7bc630378be534 to your computer and use it in GitHub Desktop.
ED Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import $ from 'jquery'; | |
// import Promise from 'rsvp'; | |
import DS from 'ember-data'; | |
export default DS.Adapter.extend({ | |
findRecord(store, type, id, snapshot) { | |
return {'imgURL': 'New Img comes here'}; | |
}, | |
createRecord(store, type, snapshot){ | |
let data = this.serialize(snapshot, { includeId: true }); | |
data.id = 0; | |
return data; | |
}, | |
updateRecord(store, type, snapshot){ | |
}, | |
deleteRecord(store, type, snapshot){ | |
}, | |
findAll(store, type, sinceToken){ | |
}, | |
query(store, type, query){ | |
}, | |
// // optional, to increase speed | |
// findMany(store, type, ids, snapshots){ | |
// } | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Data example', | |
init() { | |
var this_self = this; | |
this.get('store').createRecord('simple-data', { | |
id: 0, | |
imgURL: 'ABCDEFGHIJK' | |
}); | |
this.get('store').findRecord('simple-data', 0).then(function(dt){ | |
let dataImgURL = dt.get('imgURL'); | |
this_self.set('imgURL', dataImgURL); | |
}); | |
}, | |
actions: { | |
applyNewData() { | |
this.get('store').findRecord('simple-data', 0).then(function(dt){ | |
dt.set('imgURL', 'XYZ'); // How to reflect this on the template automatically? | |
}); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
imgURL: attr('string'), | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
export default DS.Serializer.extend({ | |
serialize(snapshot, options){ | |
var json = this._super(...arguments); | |
return json; | |
}, | |
normalizeResponse(store, primaryModelClass, payload, id, requestType) { | |
var attrHash = {}; | |
attrHash['id'] = 0; // Self user | |
attrHash['imgURL'] = payload['imgURL']; | |
let JSONAPIData = this.normalize(primaryModelClass, attrHash); | |
return JSONAPIData; | |
}, | |
normalize(modelClass, resourceHash) { | |
var data = { | |
id: resourceHash.id, | |
type: modelClass.modelName, | |
attributes: resourceHash | |
}; | |
return { data: data }; | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.12.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0" | |
}, | |
"addons": { | |
"ember-data": "2.12.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment