Skip to content

Instantly share code, notes, and snippets.

@tomdale
tomdale / gist:3981133
Last active November 26, 2019 21:19
Ember.js Router API v2

WARNING

This gist is outdated! For the most up-to-date information, please see http://emberjs.com/guides/routing/!

It All Starts With Templates

An Ember application starts with its main template. Put your header, footer, and any other decorative content in application.handlebars.

<header>
@tomdale
tomdale / gist:4263171
Created December 11, 2012 23:05
Ember Data Read-Only API Proposal

Read-Only

An important feature for Ember Data is providing helpful error messages when your application tries to do something that is forbidden by the data model.

To that end, we would like for the data model to be able to mark certain records, attributes, and relationships as read-only. This ensures that we can provide errors immediately, and not have to wait for a return trip from the adapter.

This also means that the adapter does not need to handle the case where an application developer inadvertently makes changes to a record that it does not conceptually make sense to modify on the client.

Requirements

@tomdale
tomdale / proposal.md
Last active October 16, 2019 09:01
Ember Data / Ember Ajax / Ember Fetch proposal

Networking in Ember

Motivation

Most client-side applications need to fetch data over the network. In the Ember.js ecosystem, many developers use a high-level abstraction, like Ember Data, that standardizes network access via an adapter pattern.

For those who want more low-level control over data fetching, it is

@tomdale
tomdale / action.js
Created October 4, 2019 23:59
bind vs. action decorators
import Component, { tracked, action } from '@glimmer/component';
export default class extends Component {
@tracked count = 0;
@action increment() {
this.count++;
}
}
@tomdale
tomdale / .vsls.json
Created July 11, 2019 18:40
Visual Studio Live Share gitignore configuration
{
"$schema": "http://json.schemastore.org/vsls",
"gitignore":"none"
}
@tomdale
tomdale / class-template.ts
Created June 4, 2019 13:58
Class Template Strawman
import Component, { gbs } from '@glimmer/component';
export default class extends Component {
static template = gbs`
<h1>Hello {{this.world}}</h1>
`
}

Forwarding Named Blocks in Glimmer

Use Case

A component that "forwards" passed blocks to a child component. For example, imagine we have a component called MiniCard that accepts a named block called header. It is invoked like this:

<MiniCard>
  <:header>
 My Card
@tomdale
tomdale / survey.md
Last active December 22, 2018 08:27
Ember Component Lifecycle Hooks Survey

Component Lifecycle Hooks Survey

Most Ember developers are familiar with component lifecycle hooks, like didInsertElement, willDestroy, etc.

As we think about future APIs for Glimmer components that improve on lifecycle hooks, we want to make sure that we're providing abstractions that are simple, performant, and ergonomic, while nudging users towards good patterns and away from potential footguns.

@tomdale
tomdale / index.js
Created December 6, 2018 13:38
Tracked property notify API strawman
import Timer from 'simple-timer';
import Component from '@glimmer/component';
import { } from '@glimmer/tracking';
export default class TimerComponent extends Component {
constructor() {
// Mark the timer as "untracked" (i.e., we're asserting
// that timer contains no interior tracked properties at all).
// This function gives us back the timer as well as a callback
// function to call when any interior mutation may have occurred.
@tomdale
tomdale / local-storage-array.js
Created April 28, 2014 02:12
Ember Array that writes every change to localStorage
export default Ember.ArrayProxy.extend({
localStorageKey: null,
init: function() {
var localStorageKey = this.get('localStorageKey');
if (!localStorageKey) {
throw new Error("You must specify which property name should be used to save " + this + " in localStorage by setting its localStorageKey property.");
}