Skip to content

Instantly share code, notes, and snippets.

View RickButler's full-sized avatar

Rick Butler RickButler

View GitHub Profile
var AmpersandModel = require('ampersand-model');
var get = require('lodash/get');
var includes = require('lodash/includes');
AmpersandModel.extend({
session: {
fetched: 'boolean',
saved: 'boolean',
destroyed: 'boolean'
},
var app = require('ampersand-app');
var baseView = require('../_core/base');
var CollectionView = require('ampersand-collection-view')
var collectionView = require('../gameobject/recipe-view');
var GameObjectMenu = require('../gameobjects/gameobjectmenu-view');
var templates = require('../../templates');
module.exports = baseView.extend({
pageTitle: 'Recipes',
template: templates.pages.gameobjects.recipes,
@RickButler
RickButler / Fetch Children
Last active January 12, 2016 14:45
A helper method for an ampersand-view / ampersand-model to fetch the children if they have a url and fetch method.
var View = require('ampersand-view'); // you can use ampersand-model/ampersand-state here too
var _ = require('lodash');
module.exports = View.extend({
fetchChildren: function(options) {
_.chain(this._children)
.keys()
.each(function(key) {
if(_.isFunction(this[key].url) && _.isFunction(this[key].fetch) {
this[key].fetch(options);
@RickButler
RickButler / Fetched Model
Last active January 12, 2016 14:43
An ampersand model that replaces the idAttribtue in isNew with fetched property that is set after the model performs a get/fetch, this property can also be used for waitFor.
var Model = require('ampersand-model');
var _ = require('lodash');
module.exports = Model.extend({
constructor: function(){
Model.apply(this, arguments);
_.bindAll(this, 'onSync');
this.on('sync', this.onSync);
},
isNew: function(){