Last active
October 9, 2019 08:05
-
-
Save basz/5bea96d4b954207d81d07955b51bcca7 to your computer and use it in GitHub Desktop.
New Twiddle
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' | |
}); |
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 { helper } from '@ember/component/helper'; | |
import { isNone } from '@ember/utils'; | |
export default helper((params, hash) => { | |
const [json] = params; | |
let { pretty } = hash; | |
pretty = isNone(pretty); | |
return JSON.stringify(json, null, pretty ? 2 : null); | |
}); |
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'; | |
const { Model, attr } = DS; | |
export default Model.extend({ | |
prop: attr('string', { | |
defaultValue: () => { | |
return '1'; | |
} | |
}) | |
}); |
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'; | |
import MF from 'ember-data-model-fragments'; | |
export default MF.Fragment.extend({ | |
prop: DS.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 DS from 'ember-data'; | |
const { Model, attr, belongsTo } = DS; | |
import { fragment } from 'ember-data-model-fragments/attributes'; | |
export default Model.extend({ | |
prop: attr('string', { | |
defaultValue: () => { | |
return '1'; | |
} | |
}), | |
fragment: fragment('fragment'), | |
child: belongsTo('child', { | |
defaultValue: () => { | |
return { 'prop': '1' }; | |
} | |
}), | |
}); |
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 Route from '@ember/routing/route'; | |
import { inject as service } from '@ember/service'; | |
import Changeset from 'ember-changeset'; | |
import lookupValidator from 'ember-changeset-validations'; | |
import { validatePresence } from 'ember-changeset-validations/validators'; | |
const validations = { | |
'prop': [validatePresence({ presence: true, allowBlank: true })], | |
'child.prop': [validatePresence({ presence: true, allowBlank: true })], | |
'fragment.prop': [validatePresence({ presence: true, allowBlank: true })] | |
}; | |
export default Route.extend({ | |
store: service(), | |
model() { | |
// create child | |
const child = this.store.createRecord('child'); | |
// create a fragment | |
const fragment = this.store.createFragment('fragment', {prop: null}); | |
// create root, with relationship and fragment | |
const model = this.store.createRecord('root', { child, fragment }); | |
// create changeset | |
const changeset = new Changeset(model, lookupValidator(validations), validations); | |
changeset.validate(); | |
return { model, changeset }; | |
}, | |
setupController(controller, model) { | |
controller.setProperties(model); | |
} | |
}); |
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.15.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.4.3", | |
"ember-template-compiler": "3.4.3", | |
"ember-testing": "3.4.3", | |
"bootstrap": "4.3.1" | |
}, | |
"addons": { | |
"ember-data": "3.4.2", | |
"ember-bootstrap": "2.8.1", | |
"ember-bootstrap-changeset-validations": "2.0.0", | |
"ember-changeset": "2.1.2", | |
"ember-changeset-validations": "2.1.0", | |
"ember-data-model-fragments": "4.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment