From 0fe1fd2a825d4e267a0283db37bd8343fa8a3648 Mon Sep 17 00:00:00 2001 From: dsc Date: Thu, 29 Mar 2012 01:36:06 -0700 Subject: [PATCH] Removes backbone.nested, as it breaks assignment with empty containers. --- lib/base.co | 66 +++++++++++++++++++++++++++++++++++++++++++++---- lib/util/backbone.co | 6 ++++ 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/lib/base.co b/lib/base.co index 27788f4..f1e6235 100644 --- a/lib/base.co +++ b/lib/base.co @@ -1,20 +1,65 @@ _ = require 'kraken/underscore' op = require 'kraken/util/op' +Backbone = require 'backbone' + + /** * @class Base model, extending Backbone.Model, used by scaffold and others. * @extends Backbone.Model */ BaseModel = exports.BaseModel = Backbone.Model.extend do # {{{ + ctorName : 'BaseModel' + # A list of method-names to bind on initialize; set this on a subclass to override. __bind__ : [] - ctorName : 'BaseModel' + + + + constructor : function BaseModel + @__class__ = @constructor + @__super__ = @constructor.__super__ + @__superclass__ = @__super__.constructor + # Backbone.NestedModel.apply this, arguments + Backbone.Model.apply this, arguments + # @trigger 'create', this initialize: -> - @__super__ = @constructor.__super__ _.bindAll this, ...@__bind__ if @__bind__.length + + ### Accessors + + has: (key) -> + @get(key)? + + get: (key) -> + _.getNested @attributes, key + + # set: (key, value, opts) -> + # if _.isObject(key) and key? + # [values, opts] = [key, value] + # else + # values = { "#key": value } + # + # # TODO: Validation + # @_changed or= {} + # + # for key, value in values + # if _.str.contains key, '.' + # _.setNested @attributes, key, value, opts + # else + # @__super__.set.call this, key, value, opts + # + # this + # + # unset : (key, opts) -> + # + + + ### Serialization + serialize: (v) -> # if v!? # v = '' @@ -47,8 +92,8 @@ BaseModel = exports.BaseModel = Backbone.Model.extend do # {{{ /** * @returns {String} URL identifying this model. */ - toURL: (item_delim='&', kv_delim='=') -> - "?#{@toKV()}" + toURL: -> + "?#{@toKV ...}" toString: -> "#{@ctorName}(id=#{@id})" @@ -77,6 +122,15 @@ BaseModel import do BaseList = exports.BaseList = Backbone.Collection.extend do # {{{ ctorName : 'BaseList' + # A list of method-names to bind on initialize; set this on a subclass to override. + __bind__ : [] + + + initialize : -> + @__super__ = @constructor.__super__ + _.bindAll this, ...@__bind__ if @__bind__.length + + toKVPairs: -> _.collapseObject @toJSON() @@ -97,14 +151,14 @@ BaseList = exports.BaseList = Backbone.Collection.extend do # {{{ BaseView = exports.BaseView = Backbone.View.extend do # {{{ ctorName : 'BaseView' - # List of methods to bind on initialize; set on subclass + # A list of method-names to bind on initialize; set this on a subclass to override. __bind__ : [] initialize: -> - _.bindAll this, ...@__bind__ if @__bind__.length @__super__ = @constructor.__super__ + _.bindAll this, ...@__bind__ if @__bind__.length @model.view = this @$el.data { @model, view:this } diff --git a/lib/util/backbone.co b/lib/util/backbone.co index ee7276c..d867674 100644 --- a/lib/util/backbone.co +++ b/lib/util/backbone.co @@ -1,7 +1,13 @@ + +# Expose Underscore so Backbone can find it _ = require 'underscore' window?._ = _ + +# Expose Backbone so plugins can find it Backbone = require 'backbone' window?.Backbone = Backbone + +# Pass jQuery to Backbone, as it only looks on its module if `require` is defined Backbone.setDomLibrary that if window? and (window.jQuery or window.Zepto or window.ender) -- 1.7.0.4