Skip to content

Instantly share code, notes, and snippets.

@poulet42
Last active May 23, 2022 14:24
Show Gist options
  • Save poulet42/bfb26126ce9eccae3b6ae3152e573115 to your computer and use it in GitHub Desktop.
Save poulet42/bfb26126ce9eccae3b6ae3152e573115 to your computer and use it in GitHub Desktop.
test
import Component from '@glimmer/component';
import { dropTask, restartableTask } from 'ember-concurrency';
import { tracked } from '@glimmer/tracking';
export default class extends Component {
@tracked selectedCountry;
countries = [
"france",
"italy",
"germany",
]
@dropTask *handleSelectCountryTask(country) {
this.selectedCountry = country;
yield this.args.onSelectCountry(country);
}
}
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
}
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
export default class HomeController extends Controller {
@service router;
@action
handleSelectCountry(id) {
console.log(this.router);
return this.router.transitionTo("success", id)
}
}
import Controller from '@ember/controller';
export default Controller.extend({
});
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('home', {path: "/"})
this.route('success', {path: '/success/:id'})
});
export default Router;
import Route from '@ember/routing/route';
export default class HomeRoute extends Route {
async model({ id }) {
return id
}
}
import Route from '@ember/routing/route';
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
export default class SuccessRoute extends Route {
async model({ id }) {
await sleep(5000);
return id
}
}
<h2>Select your country</h2>
{{#each this.countries as |country|}}
<button {{on "click" (perform this.handleSelectCountryTask country)}}>
{{country}}
{{if (and (eq this.selectedCountry country) this.handleSelectCountryTask.isRunning) " | LOADING..."}}
</button>
{{/each}}
<h1>Homepage</h1>
<CountrySelector @onSelectCountry={{this.handleSelectCountry}} />
<h1>Success</h1>
You selected {{this.model}}
{
"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",
"ember-concurrency": "2.2.1",
"ember-truth-helpers": "3.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment