Skip to content

Instantly share code, notes, and snippets.

@vinicius5581
Last active May 17, 2020 06:22
Show Gist options
  • Save vinicius5581/56d12382ca590a7f5b989c95e8fdd865 to your computer and use it in GitHub Desktop.
Save vinicius5581/56d12382ca590a7f5b989c95e8fdd865 to your computer and use it in GitHub Desktop.
Ember Fun
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
appName = 'Ember Fun';
}
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('contacts', { path: '/contacts' }, function() {
// this.route('contact', { path: '/:post_id' });
this.route('index', { path: '/' });
})
this.route('contact', { path: '/contacts/:contact_id' });
});
export default Router;
import Route from '@ember/routing/route';
const contactsData = [
{
id: 1,
name: 'Dolly',
slug: 'dolly'
},
{
id: 2,
name: 'kitty cat',
slug: 'kitty-cat'
},
{
id: 3,
name: 'Cleopatra',
slug: 'cleo'
}
];
export default Route.extend({
sayOi: on('activate', function(){
console.log("oi");
})
model() {
return contactsData;
// return this.get('store').findAll('contact'); // with mirage or live api
}
});
<h1>Welcome to {{this.appName}}</h1>
<br>
<nav>
<LinkTo @route="index">Home</LinkTo>
<LinkTo @route="contacts">Contacts</LinkTo>
</nav>
<br>
<br>
templates/application.hbs
<br>
{{outlet}}
<br>
<br>
templates/contacts/contact.hbs
templates/contacts/index.hbs
templates/contacts.hbs
{{this.sayOi}}
<br>
{{outlet}}
templates/index.hbs
import Application from '../app';
import config from '../config/environment';
import { setApplication } from '@ember/test-helpers';
import { assign } from '@ember/polyfills';
import { start } from 'ember-qunit';
let attributes = {
rootElement: '#test-root',
autoboot: false
};
attributes = assign(attributes, config.APP);
let application = Application.create(attributes);
setApplication(application);
start();
{
"version": "0.17.1",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
"_APPLICATION_TEMPLATE_WRAPPER": true,
"_JQUERY_INTEGRATION": true
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js",
"ember": "3.18.1",
"ember-template-compiler": "3.18.1",
"ember-testing": "3.18.1"
},
"addons": {
"@glimmer/component": "1.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment