Skip to content

Instantly share code, notes, and snippets.

View ColinCampbell's full-sized avatar

Colin Campbell ColinCampbell

View GitHub Profile
var matchersForFilter = function(properties) {
var attributes = util.keys(properties);
var attributesFilters = util.values(properties);
var arrayOfMatchersForAttribute = util.map(
util.zip(attributes, attributesFilters), matchersForAttribute
);
var matchers = util.flatten(arrayOfMatchersForAttribute, true);
return matchers;
var matchersForFilter = function(properties) {
var attributes = util.keys(properties);
var attributesFilters = util.values(properties);
var arrayOfMatchersForAttribute = util.map(util.zip(attributes,
attributesFilters),
matchersForAttribute);
var matchers = util.flatten(arrayOfMatchersForAttribute, true);
return matchers;
myRestrictedProp: function(key, value) {
myAllowedValues = ['here', 'there'];
if (value !== undefined) {
if (myAllowedValues.indexOf(value) === -1) {
throw "You tried to set a value that isn't allowed! " + value;
} else {
this._myRestrictedProp = value;
}
}
@ColinCampbell
ColinCampbell / action_support.js
Created September 21, 2011 17:48
mixins/action_support.js
// ==========================================================================
// Project: SproutCore - JavaScript Application Framework
// Copyright: ©2006-2011 Strobe Inc. and contributors.
// Portions ©2008-2011 Apple Inc. All rights reserved.
// License: Licensed under MIT license (see license.js)
// ==========================================================================
var get = SC.get, set = SC.set, getPath = SC.getPath;
/**
MyApp.someController = SC.Object.create({
nowShowing: "index"
});
MyApp.Application = SC.Record.extend({
assignments: function() {
var data = this._data_assignments,
id = this.get('id'), query;
if (!data && id) {
query = SC.Query.local(MyApp.Assignment, 'application = {application}', {application: this});
data = this._data_assignments = MyApp.get('store').find(query);
}
// ==========================================================================
// Project: SproutCore - JavaScript Application Framework
// Copyright: ©2006-2011 Strobe Inc. and contributors.
// Portions ©2008-2011 Apple Inc. All rights reserved.
// License: Licensed under MIT license (see license.js)
// ==========================================================================
var get = SC.get, set = SC.set, getPath = SC.getPath;
/**
@ColinCampbell
ColinCampbell / core.js
Created July 20, 2011 08:23 — forked from justinpeterman/core.js
Nested Records
Authoring = SC.Application.create(
store: SC.Store.create().from(SC.Record.fixtures)
}) ;
var data = MyApp.store.find([Scm.Product, Scm.Taxon]);
data.addObserver('status', this, function observer() {
if (data.get('status') === SC.Record.READY_CLEAN) {
data.removeObserer('status', this, observer);
var products = data.find(SC.Query.local(Scm.Product));
var taxons = data.find(SC.Query.local(Scm.Taxon));
}
});
// ==========================================================================
// Project: SproutCore Handlebar Views
// Copyright: ©2011 Strobe Inc. and contributors.
// License: Licensed under MIT license (see license.js)
// ==========================================================================
var get = SC.get, set = SC.set;
SC.SelectOption = SC.View.extend({