Skip to content

Instantly share code, notes, and snippets.

@hotsoft-desenv4
Last active May 29, 2020 18:54
Show Gist options
  • Save hotsoft-desenv4/fe8768f91acd2b647c4163447db9d909 to your computer and use it in GitHub Desktop.
Save hotsoft-desenv4/fe8768f91acd2b647c4163447db9d909 to your computer and use it in GitHub Desktop.
Glimerless controllfreak functional redirectioninzing full version
app/components/marcas/marcas-form.js
import Component from '@ember/component';
export default Component.extend({
//https://guides.emberjs.com/v3.3.0/components/triggering-changes-with-actions/
//https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/closure-actions.md
actions: {
saveMarca(marca) {
let selfthis = this;
marca.save().then( function() {
selfthis.sendAction('redirectTo');
});
}
}
});
app/components/marcas/marcas-index.js
import Component from '@ember/component';
export default Component.extend({
actions: {
deleteMarca(marca) {
marca.destroyRecord();
}
}
});
app/templates/marcas/new.hbs
<h2>Criar nova marca</h2>
{{marcas/marcas-form
model=model
redirectTo=(action "redirectTo")
}}
app/controllers/marcas/new.js
import Controller from '@ember/controller';
import { action } from '@ember/object';
export default class MarcasNewController extends Controller {
@action
redirectTo() {
this.transitionToRoute("/marcas");
}
}
app/routes/marcas/new.js
import Route from '@ember/routing/route';
export default Route.extend({
model() {
return this.store.createRecord('marca');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment