Skip to content

Instantly share code, notes, and snippets.

@bortevik
bortevik / pure_computed.js
Last active May 2, 2017 11:21
Pure computed
pure(...args) {
const f = args.pop();
return Ember.computed(...args, function() {
const values = args.map(arg => {
if (arg.match(/@each/)) {
const segments = arg.split('.@each.');
return this.get(segments[0]).map(v => v.get(segments[1]));
} else if (arg.match(/\[\]/)) {
const segments = arg.split('.[]');
return this.get(segments[0]);
@bortevik
bortevik / gist:c9310ab768e9baa5335a
Created November 18, 2014 07:11
LocalStorage wraper
App.StorageService = Ember.Object.extend({
persistence: window.localStorage,
namespace: 'ember-storage-service',
init: function() {
var callback = this._handleStorageEvent.bind(this);
$(window).on('storage', callback);
},
@bortevik
bortevik / gist:9324966
Last active August 29, 2015 13:56
Uploading Files with CORS and Ember.js
# View
RoscredAdmin.UploadFileView = Ember.TextField.extend
classNames: ['form-control']
attributeBindings: ['name']
type: 'file'
file: null
change: (event)->
fd = new FormData()
fd.append('pdf', event.target.files[0])
@set('file', fd)