Created
March 20, 2017 15:11
-
-
Save Sinled/af89f2519d956f4eacf9665277b91908 to your computer and use it in GitHub Desktop.
check-double-save
This file contains 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.JSONAPIAdapter.extend({ | |
createRecord(...params) { | |
alert('createRecord'); | |
return Ember.RSVP.Promise.resolve({ | |
data: { | |
type: 'tournament', | |
id: Date.now(), | |
attributes: { | |
title: 'updated world' + (new Date) | |
} | |
} | |
}) | |
} | |
}); |
This file contains 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 Twiddle', | |
actions: { | |
saveTournament(tournament) { | |
alert('save'); | |
tournament.save(); | |
} | |
} | |
}); |
This file contains 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 Ember from 'ember'; | |
const { inject, computed, isEmpty, RSVP: { Promise } } = Ember; | |
export function initialize(/* application */) { | |
Model.reopen({ | |
save() { | |
alert('redefined save'); | |
if (this.get('validations.isInvalid')) { | |
return Promise.reject('Falid to save'); | |
} | |
return this._super(); | |
} | |
}); | |
} | |
export default { | |
name: 'model-save-extend', | |
initialize | |
}; |
This file contains 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"; | |
import { validator, buildValidations } from 'ember-cp-validations'; | |
const Validations = buildValidations({ | |
title: validator('presence', true), | |
}); | |
export default Model.extend(Validations, { | |
title: attr('string') | |
}); |
This file contains 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.Route.extend({ | |
model() { | |
return this.store.createRecord('tournament', { title: 'hello world' }); | |
} | |
}); |
This file contains 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.11.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.11.0", | |
"ember-data": "2.11.0", | |
"ember-template-compiler": "2.11.0", | |
"ember-testing": "2.11.0" | |
}, | |
"addons": { | |
"ember-cp-validations": "3.2.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment