Skip to content

Instantly share code, notes, and snippets.

@rondale-sc
Last active September 5, 2018 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rondale-sc/0b8a34408e204f39b9a8c76d55b07dfe to your computer and use it in GitHub Desktop.
Save rondale-sc/0b8a34408e204f39b9a8c76d55b07dfe to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
import { inject as service } from '@ember/service';
import { getOwner } from '@ember/application';
export default Ember.Controller.extend({
routerService: service('router'),
appName: 'Ember Twiddle',
actions: {
actionOne() {
this.get('routerService').transitionTo('foo.bar.my-route', 1, { queryParams: { foo: 1 }});
},
actionTwo() {
let routerMain = getOwner(this).lookup('router:main');
routerMain.transitionTo('foo.bar.my-route', 2, { queryParams: { foo: 2 }});
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
queryParams: ['foo']
});
import EmberRouter from '@ember/routing/router';
import config from './config/environment';
const Router = EmberRouter.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('foo', { path: '/foo/:id' }, function() {
this.route('bar', function() {
this.route('my-route');
});
});
this.route('quux');
});
export default Router;
import Ember from 'ember';
import { inject as service } from '@ember/service'
import { getOwner } from '@ember/application';
export default Ember.Route.extend({
routerService: service('router'),
actions: {
actionThree() {
this.get('routerService').transitionTo('foo.bar.my-route', 3, { queryParams: { foo: 3 }});
},
actionFour() {
let routerMain = getOwner(this).lookup('router:main');
routerMain.transitionTo('foo.bar.my-route', 4, { queryParams: { foo: 4 }});
}
}
});
import Ember from 'ember';
import { inject } from '@ember/service';
export default Ember.Route.extend({
routerService: inject('router'),
beforeModel() {
this.get('routerService').transitionTo('foo.bar.my-route', 1, { queryParams: { foo: 1 }});
}
});
<button {{action 'actionOne' }}> Action1 </button>
<button {{action 'actionTwo' }}> Action2 </button>
<button {{action 'actionThree' }}> Action3 </button>
<button {{action 'actionFour' }}> Action4 </button>
{{link-to 'quux' 'quux'}}
{{outlet}}
{{link-to 'Home' 'index' }}
import { run } from '@ember/runloop';
export default function destroyApp(application) {
run(application, 'destroy');
}
import Resolver from '../../resolver';
import config from '../../config/environment';
const resolver = Resolver.create();
resolver.namespace = {
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix
};
export default resolver;
import Ember from 'ember';
import Application from '../../app';
import config from '../../config/environment';
const { run } = Ember;
const assign = Ember.assign || Ember.merge;
export default function startApp(attrs) {
let application;
let attributes = assign({rootElement: "#test-root"}, config.APP);
attributes = assign(attributes, attrs); // use defaults, but you can override;
run(() => {
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
return application;
}
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
import { start } from 'ember-cli-qunit';
setResolver(resolver);
start();
{
"version": "0.15.0",
"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.2.2",
"ember-template-compiler": "3.2.2",
"ember-testing": "3.2.2"
},
"addons": {
"ember-data": "3.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment