Skip to content

Instantly share code, notes, and snippets.

@visualjeff
visualjeff / gist:8c04d19680293fdb2af7c69023022563
Last active July 30, 2016 22:24
Ember Component Learnings
Ember Component Learnings:
==========================
Don't ever assign a dynamic value to a id or name attribute of a field
Don't share state between components. Always reset or init properties via the init method. Same for mixins.
Warning:
========
Because components are sealed from outside events. It challenging to
get them to refresh on command. To pull this off you essentially need
them to observe a property on a controller in order to get them to refresh.
JSONAPI - Kabab case only. No camel case
data
type (plural)
id (string of a number)
attributes (payload)
relationships (minial JSONAPI form inside. Type (can be singular or plural) and id. can also be an Array)
links (optional but ember-data does support links)
included (optional. Type, id and attributes. Always an Array)
====================================================================
@visualjeff
visualjeff / gist:f6ebbe05d24939a71caddbbaab218ff2
Last active July 30, 2016 22:16
Ember-Data Serializer Notes
Ember Data Notes:
Serializers
Either you are:
1. deserialization - data from the server, extract then normalize
2. serialization - Sending data to the server
You can define an alternate primary key in the serializer:
@visualjeff
visualjeff / gist:a37ea04650e8a4de2a3a8953f09b0cd4
Created July 30, 2016 21:56
Javascript's Higher Order Functions and Ember's Higher Order functions
Higher order functions:
.forEach() - Iterates over a set
.map() - Projects a set
.filter() - Narrows down a set based on the predicate
.find() - Returns the first match in a set based on the predicate
.any() - Returns true if match is found based on the predicate
.every() - Returns true if match is found for all elements in the set (predicate also)
Stop using switch, for and while loops!
Mirage cheatsheet:
1. Install Mirage: ember install ember-cli-mirage
2. Set namespace in mirage/config.js
3. Set route handler in mirage/config.js
4. Generate mirage model. ember g mirage-model <model_name>
5. If you not using JSONAPI. Customize your mirage serializer
6. Seed the database: ember g mirage-fixture <fixture_name>
7. Remove senarios directory. It prevents fixtures being load. rm -rf senarios
8. Refactor to use shorthands where possible.
import Ember from 'ember';
export default Ember.Component.extend({
didInsertElement: function() {
this.set('options', {
// the element holding pannable content area
contentEl: Ember.$(this.element).find('.ptr-content')[0],
// the element holding pull to refresh loading area
ptrEl: Ember.$(this.element).find('.ptr-indicator')[0]
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 50px;
NOTE: While this is an easy fix. Its doesn't work so well with Ember.
Also there are trade offs. Mobiles apps will be forced to scroll out of the gate.
@visualjeff
visualjeff / gist:d27392719fd96955ae006865f95b9e83
Created June 30, 2016 22:07
How to add code complete for Node.js in Visual Studio Code.
sudo npm install typings --global
typings search --name node
typings install env~node --global --save
Then I added the following to the top of my index.js file.
/// <reference path="typings/index.d.ts"/>
@visualjeff
visualjeff / gist:aefec63d012873b2b8032810c2730ba6
Created May 14, 2016 20:59
Ember-data JSONAPIAdapter override to address case issues. Camel-case versus kabab-case.
pathForType: function(type) {
type = this._super(...arguments);
if (type === 'building-types') {
type = type.camelize(); //Node API is expects a camelized path for this api signature. i.e., buildingTypes
}
return type;
},
@visualjeff
visualjeff / gist:ffdf0eaa1ba02104be47664e79a84865
Created May 14, 2016 20:57
Ember-data JSONAPIAdapter override to append rev to delete requests for couchdb.
urlForDeleteRecord(id, modelName, snapshot) {
return this._super(...arguments) + `?rev=${snapshot._attributes.rev}`;
}