Skip to content

Instantly share code, notes, and snippets.

@jugglinmike
jugglinmike / ember-model-deep-rollback.js
Last active May 31, 2016 10:50
Ember Mixin for Ember-Data Models
define(function(require) {
'use strict';
var Ember = require('ember');
return Ember.Mixin.create({
/**
* Cache all relationship IDs each time the model is loaded or updated.
* This data is required to determine if any relationships contain new
* records (or omit old records) since the last server synchronization
* (see this mixin's `areRelationshipsDirty` and `rollbackRelationships`
@jugglinmike
jugglinmike / first-change.js
Created May 30, 2014 19:11
Experimenting with "firstChange" event in Ember
var onNextChange = function(model, handler, context) {
var fields = Ember.get(model.constructor, 'fields').keys.toArray();
// Avoid multiple invocations from batched changes using a boolean guard.
var hasChanged = false;
var handleChange = function() {
if (hasChanged) {
return;
}
hasChanged = true;
@jugglinmike
jugglinmike / window-emitter.js
Last active August 29, 2015 13:57
A Backbone Event wrapper for browser window events
define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {
'use strict';
var WindowEmitter = _.extend({}, Backbone.Events);
var $window = $(window);
// 0.1 second is about the limit for having the user feel that the
// system is reacting instantaneously, meaning that no special feedback
// is necessary except to display the result.
// Source: http://www.nngroup.com/articles/response-times-3-important-limits/
var period = 100;
@jugglinmike
jugglinmike / package.json
Created March 16, 2014 03:35
Concise use of AMDefine and Chai for TimmyB
{
"scripts": {
"test": "mocha --require test/setup.js tests"
}
}
@jugglinmike
jugglinmike / test-cases.md
Last active August 29, 2015 13:57
Valid module definition formats

Valid Module Definition Formats

  • ES6
    • with dependencies
      • export default + assignment expression
      • export + declaration
    • without dependencies
      • export default + assignment expression
      • export + declaration
  • Common JS
@jugglinmike
jugglinmike / amd.js
Last active August 29, 2015 13:57
Converting AMD early returns to generic equivalent
define(function() {
if (true) {
return 23;
}
return 45;
});
@jugglinmike
jugglinmike / question.md
Created February 27, 2014 20:36
Optimizing bower_components

I'm having trouble using r.js to optimize modules in the bower_components/ directory.

My basic project directory structure looks like this:

- bower_components/
- src/
  - activities/
  - client/

...and the r.js configuration lists the following details:

@jugglinmike
jugglinmike / main.js
Created February 12, 2014 02:36
RequireJS confusion
require.config({
paths: {
"alias-path": "real-path"
}
});
require(["real-path", "alias-path"], function(r, a) {
// never invoked
});
@jugglinmike
jugglinmike / nin-macro.js
Created January 22, 2014 00:25
suite.js: `nin` operator macro
// Use suite.js to define a JavaScript macro for a "not in" operator
// http://sweetjs.org/
macro nin {
rule infix {
$key:expr | $obj:expr
} => {
!($key in $obj)
}
}