Skip to content

Instantly share code, notes, and snippets.

@sylwiaeb
sylwiaeb / components.my-component.js
Created November 22, 2019 17:14 — forked from feanor07/components.my-component.js
Stackoverflow Question#43112479
import Ember from 'ember';
export default Ember.Component.extend({
selected: {name: 'All', id:0},
computedOptions: Ember.computed('options.[]', function(){
return this.get('options').slice().insertAt(0, this.get('selected'));
})
});
import Ember from 'ember';
export default Ember.Component.extend({
tagName: ''
});
import Ember from 'ember';
export default Ember.Component.extend({
});
@sylwiaeb
sylwiaeb / route-test.js
Created April 16, 2018 18:42 — forked from benbabics/route-test.js
Ember Mock Service
import Ember from 'ember';
import { moduleFor, test } from 'ember-qunit';
let mockSession = Ember.Service.extend({
isAuthenticated: true,
currentUser: Ember.computed('isAuthenticated', function() {
return Ember.RSVP.Promise(function(resolve) {
resolve( Ember.Object.create({ accounts: [] }) );
});
})
@sylwiaeb
sylwiaeb / mirage-tils.org
Created March 23, 2018 14:21 — forked from abuiles/mirage-tils.org
Mirage TILS

Version: ^0.2.0-beta.5

How can I check the serialized version of a model?

server.get('api/employee's, function(schema, request) {
  employee = schema.employee.find(1);
  this.serializerOrRegistry.serialize(employee, request);

  return foo;
});
import Ember from 'ember';
export default Ember.Controller.extend({
})
@sylwiaeb
sylwiaeb / components.lazy-options.js
Created August 23, 2017 16:02 — forked from tomoguisuru/components.lazy-options.js
Power Select Custom Options
import Ember from 'ember';
import PSOptionsComponent from 'ember-power-select/components/power-select/options';
const {
$,
assert,
get,
} = Ember;
@sylwiaeb
sylwiaeb / in_viewport.js
Created May 4, 2017 20:56 — forked from jjmu15/in_viewport.js
check if element is in viewport - vanilla JS. Use by adding a “scroll” event listener to the window and then calling isInViewport().
// Determine if an element is in the visible viewport
function isInViewport(element) {
var rect = element.getBoundingClientRect();
var html = document.documentElement;
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || html.clientHeight) &&
rect.right <= (window.innerWidth || html.clientWidth)
);
@sylwiaeb
sylwiaeb / array_iteration_thoughts.md
Created March 13, 2017 10:44 — forked from ljharb/array_iteration_thoughts.md
Array iteration methods summarized

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it much simpler to think about both the old list and the new one, what they contain, and

@sylwiaeb
sylwiaeb / dirty-helpers.js
Created February 13, 2017 15:23 — forked from timrwood/dirty-helpers.js
Ember Data Dirty Relationships Mixins
import Ember from 'ember';
export { dirtyHasMany, dirtyBelongsTo, dirtyMixin };
var dirty = 'relationshipIsDirty';
function dirtyMixin (obj) {
var args = Object.keys(obj);
var comp = Ember.computed;
args.push('isDirty');
obj[dirty] = comp.any.apply(comp, args);