Skip to content

Instantly share code, notes, and snippets.

View nadnoslen's full-sized avatar
👋

Daniel Nelson nadnoslen

👋
View GitHub Profile
@nadnoslen
nadnoslen / Ember.js-2.16.imports.xml
Created January 19, 2018 21:35
A JetBrains IDE Live Template for for importing modules in your .js files.
<templateSet group="Ember.js-2.16+ Imports">
<template name="icomputed" value="import { $methods$ } from '@ember/object/computed';" description="Import the @ember/object/computed" toReformat="true" toShortenFQNames="true">
<variable name="methods" expression="enum(&quot;alias&quot;, &quot;and&quot;, &quot;bool&quot;, &quot;collect&quot;, &quot;deprecatingAlias&quot;, &quot;empty&quot;, &quot;equal&quot;, &quot;filter&quot;, &quot;filterBy&quot;, &quot;gt&quot;, &quot;gte&quot;, &quot;intersect&quot;, &quot;lt&quot;, &quot;lte&quot;, &quot;map&quot;, &quot;mapBy&quot;, &quot;match&quot;, &quot;max&quot;, &quot;min&quot;, &quot;none&quot;, &quot;not&quot;, &quot;notEmpty&quot;, &quot;oneWay&quot;, &quot;or&quot;, &quot;readOnly&quot;, &quot;reads&quot;, &quot;setDiff&quot;, &quot;sort&quot;, &quot;sum&quot;, &quot;union&quot;, &quot;uniq&quot;, &quot;uniqBy&quot;)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_SCRIPT" value="true" />
</context>
</template>
<template
@nadnoslen
nadnoslen / testem.js
Last active November 16, 2017 18:35
Ember-2.x testem.js Headless Configuration
/*jshint node:true*/
/**
* I'd suggest removing any old testem.json files in the root of your
* Ember application.
*
* With this configuration, your tests will run in Chrome by default.
*
* To run your tests in headless (FASTER) mode (launch_in_ci):
* `ember t`
@nadnoslen
nadnoslen / circle.yml
Last active August 22, 2017 22:50
CircleCI (1.0) configuration using parallelism for an EmberJS add-on (Ember-2.13+).
# This configuration file is being used by my EmberJS addon that I recently upgraded to
# Ember-2.14 (the current release at time of writing)
machine:
node:
version: 6 # My project is using Node6 for now while Node8 works through some kinks
dependencies:
cache_directories:
- '~/.npm'
- '~/.cache' # includes bower & yarn

Creating Customized JSONAPI Compliant Responses

There are times when using jsonapi-resources that you will need to write your own controller actions because you have complicated logic or a resource with relationships to process in a single transactioned request. It's nice to know how to handle the success and failure responses in a JSONAPI compliant manner. Thankfully jsonapi-resources exposes these features to us, you just need to read some code to figure out how to use them.

A Typical Success Response

Consider a use-case where you are updating a Users model and its collection of assigned Roles. Say you author an action in your users_controller.rb named update_user_and_roles:

def update_user_and_roles

... process write your logic to process the User model and the Role models...that's outside the scope of this example

  • When naming indexes in migrations, make sure to use names that do not contain any spaces.
@nadnoslen
nadnoslen / EmberJS Best Practices.md
Last active March 16, 2017 20:45
A list of EmberJS best practices for versions 2.6 and later.
  • Routes dedicated to looking up a specific id'd model should use the afterModel(resolvedModel, transition) to perform any security checks concerning whether the current user is permitted to the given route. OBVIOUSLY the server-side API should prevent access, but if it doesn't this is a place to make that happen. An example of this kind of route is users.user where the app/routes/users/user.js is responsible for looking up a user with a specific id. If the requested user model comes back from the server without a 401, you can further check the model with additional client-side logic to make sure that the current user is permitted to operate on it.
  • Events (e.g. clicks) should be handled by an action defined in the route. Use route-action helper. Why? Promotes component re-usability by it not being responsible for reacting to the event while the route serves a specific use case and can respond accordingly to the event.
  • In order to unit
@nadnoslen
nadnoslen / .gitignore
Last active February 7, 2016 00:53
Ember Hosted On AWS S3
# See http://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist
/tmp
# dependencies
/node_modules
/bower_components