Skip to content

Instantly share code, notes, and snippets.

View alexdiliberto's full-sized avatar

Alex DiLiberto alexdiliberto

View GitHub Profile
@alexdiliberto
alexdiliberto / ember-test-mock-network-request-pretender.js
Created October 1, 2018 14:39
EmberJS Testing - Mock network request in test body using Pretender
test('it renders', async function(assert) {
let server = new Pretender();
server.get('https://my-api', () => {
return [200, {}, JSON.stringify({
items: [
{
name: 'jim',
waffles: 1
},
{
@alexdiliberto
alexdiliberto / install-ember-hash-version.md
Created September 27, 2018 17:01
Install `ember-source` from specific git hash
  1. Print out the current tarball url for the release channel
npx ember-source-channel-url release|beta|canary
  1. Point to the artifact in your package.json
// ...
"ember-source": "https://s3.amazonaws.com/builds.emberjs.com/canary/shas/ff6bc16b72d3684eae644185c24b538119875bb6.tgz",
@alexdiliberto
alexdiliberto / observers-immediately-invoked.js
Created September 13, 2018 22:08
Observers are immediately invoked inline-functions
// observers are immediately invoked inline-functions
function updateState(newValue) {
this.isUpdating = true;
this.set('foo', newValue);
// all observers on `foo` will fire before we hit this line
this.isUpdating = false;
}
import Controller from '@ember/controller';
import { get, set } from '@ember/object';
import { action, computed } from '@ember-decorators/object';
export default class ApplicationController extends Controller {
init() {
super.init(...arguments);
const initial = [
{ 'email.address': 'hello@example' },
@alexdiliberto
alexdiliberto / draft-lesson
Created July 2, 2018 17:44 — forked from samselikoff/draft-lesson
To use, say you have a `lesson` from a route's `model` hook. Then you could pass `lesson` into a `{{lesson-form}}`. The form could then `lesson.createDraft()` and pass that around to all the inputs. When the form calls `draft.save()`, upon completion the adapter layer rolls the successfully-persisted changes back into the original `lesson` model.
// models/draft/lesson.js
export { default } from '../lesson';
// app/routes/application.js
export default Route.extend({
currentUser: service(),
beforeModel: renderingContext({
server() {},
client() {
return this.get('currentSession.fetch').perform().catch(console.error);
}
})
@alexdiliberto
alexdiliberto / simple-screen-ruler.md
Created June 14, 2018 20:59
User screenshot tool as a screen ruler on macOS
  • +Shift+4
  • To move around an existing box hold Space
  • Right Click or ESC to cancel the screenshot action
import Ember from 'ember';
export default Ember.Component.extend({
name: 'special tag!'
});
@alexdiliberto
alexdiliberto / resolve-config-env.js
Created April 30, 2018 23:48
Resolve `config/environment.js`
let config = getOwner(this).resolveRegistration('config:environment');
@alexdiliberto
alexdiliberto / controllers.application.js
Last active April 28, 2018 01:53
Simple Input Mask
import Ember from 'ember';
const {
get,
set
} = Ember;
export default Ember.Controller.extend({
actions: {
updateSsn(event) {