This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Override is to accomidate couchdb and that it doesn't like like to see a revision or rev | |
//when creating a record. But because our model contains a rev (which is used for updates | |
//or patch request) we need to make sure during a POST request that we cut or remove the rev | |
//property out of the payload. Since Ember-Data sets it to null (record is about to be added) | |
//removing it won't hurt a thing. | |
serialize(snapshot, options) { | |
let data = this._super(...arguments); | |
if (data.data.attributes.rev === null) { | |
delete data.data.attributes.rev; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
normalizeFindAllResponse(store, primaryModelClass, payload, id, requestType) { | |
if (primaryModelClass.modelName === 'location') { // My data model in this case is location. | |
if (payload && payload.hasOwnProperty('meta')) { | |
let meta = payload.meta; | |
//Store / persist or do something your meta data. | |
delete payload.meta; | |
} | |
} | |
return this._super(...arguments); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
urlForDeleteRecord(id, modelName, snapshot) { | |
return this._super(...arguments) + `?rev=${snapshot._attributes.rev}`; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |