Skip to content

Instantly share code, notes, and snippets.

function aFunction() {
// primitives are stored directly on the stack
const foo = 1;
// obects which do not escape the scope of a function will
// be allocated on the stack and will be freed automatically
// on return
const bar = {
stack: 123
};
// Models have references to the global store
// which has a reference to the container
const Bar = DS.Model.extend({});
const Foo = Ember.Object.extend({
someData: []
});
const aFoo = Foo.create({});
// by pushing this model on to the prototype
// we've sprung a leak
const Foo = Ember.Object.extend({
// this is being placed on the Foo prototype
// and will be shared between all instances of foo
someData: []
});
const aFoo = Foo.create({});
const anotherFoo = Foo.create({});
import Ember from 'ember';
import { before, beforeEach, afterEach, after } from 'mocha';
import { getContext } from 'ember-test-helpers';
export default function(Constructor) {
return function setupTest(moduleName, options = {}) {
var module;
var contextBefore;
if (Ember.typeOf(moduleName) === 'object') {
Option<String> maybeString = someFunction();
String foo = maybeString.getOrElse("I'm some other string")
String foo2 = maybeString.getOrElse(() -> "I'm a string returned from a java lambda which has a -> instead of a =>.")
val maybeFoo:Option[String] = some_function()
val foo:String = maybeFoo.getOrElse("There was no foo!")
val foo2:String = maybeFoo.getOrElse(() => "There was no foo, so we called this function!")
# example usage, currently has one menu item, and many menu_option_items
# if there is a snapshot of the menu on the order, we use the data structures there
# instead of the ar associations
class OrderItem
include SnapshotSupport
belongs_to :menu_snapshot, through: :order
has_one :menu_item
has_many :menu_option_items
@joegaudet
joegaudet / snapshot.rb
Last active October 20, 2017 03:44
Working out the api for snapshotting
module Snapshot
class Base
attr_accessor :snapshot_type
attr_accessor :active_record_type
# serializes attributes and relationships as a hash for storage in json B columns
def serialize
end
export class AppConfiguration {
// attributes
id: number;
key: string;
preferences: string;
// relationships
versions:Version[];
}
@joegaudet
joegaudet / command-support.rb
Created October 9, 2017 16:46
command-macro
# example usage
class SomeService
# lets say Foo and Bar are AR models so they will be injected as classes
# I've been cooking up a further idea here to perhaps decorate the service
# call with another kind of dependency that would allow you to map the params
# to AR models or something... still a WIP though
dependency :foo_dao, Foo
dependency :bar_dao, Bar