Skip to content

Instantly share code, notes, and snippets.

@kumkanillam
Forked from mmun/adapters.application.js
Created March 23, 2016 05:38
Show Gist options
  • Save kumkanillam/79b79497f8f927ccef45 to your computer and use it in GitHub Desktop.
Save kumkanillam/79b79497f8f927ccef45 to your computer and use it in GitHub Desktop.
New Twiddle
import DS from 'ember-data';
export default DS.RESTAdapter;
import Ember from 'ember';
export default Ember.Controller.extend({
saveUser(user) {
Ember.run.debounce(user, 'save', 250);
},
actions: {
saveName(user, event) {
user.set('name', event.target.value);
this.saveUser(user);
},
saveCoolness(user, event) {
user.set('isCool', event.target.checked);
this.saveUser(user);
},
saveDescription(user, event) {
user.set('description', event.target.value);
this.saveUser(user);
}
}
});
import Ember from 'ember';
$.mockjax({
type: 'GET',
url: '/users/314',
status: '200',
dataType: 'json',
responseText: {
user: {
id: '314',
isCool: true,
name: "Bob",
description: "He's a great guy."
}
}
});
$.mockjax({
type: 'PUT',
url: '/users/314',
status: '200',
dataType: 'json',
responseText: {}
});
export default Ember.Route.extend({
model() {
return this.store.findRecord('user', '314');
}
});
<h1>
Editing user
{{#if model.isSaving}}
<span style="font-size: 0.5em">(Saving...)</span>
{{/if}}
</h1>
<hr>
<p>
Name:
<input value={{model.name}}
oninput={{action 'saveName' model}}>
</p>
<p>
Are they cool?
<input type="checkbox"
checked={{model.isCool}}
onchange={{action 'saveCoolness' model}}>
</p>
<p>
Description:
<textarea value={{model.description}}
oninput={{action 'saveDescription' model}}>
</textarea>
</p>
import DS from 'ember-data';
export default DS.Model.extend({
isCool: DS.attr(),
name: DS.attr(),
description: DS.attr()
});
{
"version": "0.5.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"jquery-mockjack": "https://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.5.3/jquery.mockjax.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