Skip to content

Instantly share code, notes, and snippets.

@machty
machty / controllers.application.js
Last active October 28, 2018 00:22
New Twiddle
import Ember from 'ember';
import { subscription } from "../subscription";
import { bind } from '@ember/runloop';
import { task, timeout } from 'ember-concurrency';
export default Ember.Controller.extend({
chatRooms:[ "EmberChat", "ReactChat", "VueChat", "AngularChat"],
chatRoomName: null,
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
bar: "bar_initial",
foo: Ember.computed('bar', {
set(key, value) {
return `setter(${value})`;
@machty
machty / journal.md
Created June 18, 2018 15:22
ember-testing journal

Ember Testing Journal

We've been driving all of our Ember tests with end-to-end Capybara tests running from our Rails server for some time. There are many upsides to this approach, but Capybara tests are generally slow and brittle, so we'd likely to start investing in client-side only Ember tests that don't actually hit the server at all.

Given that I don't have a lot of experience with Ember tests, I wanted to keep a journal of first impressions and snags I encountered along the way, so that perhaps this information will be useful for documentation maintainers or whomever.

Figuring out how to stub a service in an acceptance test

Screencast of me talking through my through process

@machty
machty / some-route.js
Last active June 17, 2018 14:02
I have a user-activity service that exposes some observables that monitor the user clicking/tapping around and expose some convenience methods for generating new observables, which allows for the flexibility of consumers specifying different activity times. Refactoring this to use tasks vs observables points out a few awkward cases that could be…
import { inject as service } from '@ember/service';
import Route from '@ember/routing/route';
const DEFAULT_INACTIVITY_TIMEOUT_MS = 10 * 60 * 1000
export default Route.extend({
session: service(),
userActivity: service(),
notifications: service(),
logoutTimeoutSubscription: null,
activate() {

Guide to loading/error events and substates

In addition to the techniques described in the Asynchronous Routing Guide, the Ember Router provides powerful yet overridable conventions for customizing asynchronous transitions between routes by making use of error and loading substates.

loading substates

@machty
machty / controllers.application.js
Last active April 30, 2018 15:52
ember-concurrency starter
import Ember from 'ember';
import { task, timeout } from 'ember-concurrency';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
myTask: task(function * () {
let didConfirm = yield this.get('getConfirmation').perform("Are you sure?");
if (didConfirm) {
alert("woot");
import Ember from 'ember';
function * myGen() {
yield 1;
yield 2;
yield 3;
}
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
import Ember from 'ember';
import { task, timeout, waitForProperty } from 'ember-concurrency';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
lol: 'init',
foo: task(function * () {
this.set('lol', 1);
@machty
machty / nested-loading-routes.md
Created October 8, 2013 05:23
Proposal for nested loading routes in Ember.js

Loading Route Facelift

LoadingRoute has existed for a while, but it's barely useful and largely broken. It's never gotten much love due to it largely being a hangover of the router.js microlib, and we can make it better. The problems with LoadingRoute are intertwined with issues with facelift router's handling of async transitions in some cases, but of which need to be addressed, but here's a list of problems related to both:

  • There's only one global LoadingRoute that gets activated when