Skip to content
Browse files

fixes for appplication and enum properties

  • Loading branch information...
1 parent 7fa0154 commit 60cc30fa204ebee8863f867f2fe9368180f7f9b8 @collin committed Apr 16, 2012
View
9 lib/alpha_simprini/client/binding.coffee
@@ -3,6 +3,9 @@ _ = require "underscore"
AS.Binding = AS.Object.extend ({def}) ->
def initialize: (@context, @model, @field, @options={}, @fn=undefined) ->
+ if _.isString(@field)
+ @field = @model[@field]
+
@event = "change:#{field}"
if _.isFunction(@options)
@@ -23,7 +26,11 @@ AS.Binding = AS.Object.extend ({def}) ->
def willGroupBindings: ->
@constructor.willGroupBindings or _.isFunction(@fn)
- def fieldValue: -> @field.get()
+ def fieldValue: ->
+ if _.isArray(@field)
+ @model.readPath(@field)
+ else
+ @field.get()
def require_option: (name) ->
return unless @options[name] is undefined
View
15 lib/alpha_simprini/client/binding/input.coffee
@@ -4,16 +4,25 @@ _ = require "underscore"
AS.Binding.Input = AS.Binding.Field.extend ({def}) ->
def initialize: ->
@_super.apply(this, arguments)
- @context.binds @field, "change", @setContent, this
+ if _.isArray @field
+ @context.binds @model, @field, @setContent, this
+ else
+ @context.binds @field, "change", @setContent, this
def makeContent: ->
@context.$ @context.input(@options)
def bindContent: ->
- @context.binds @content, "change", _.bind(@setField, this)
+ if _.isArray @field
+ @context.binds @model, @field, @setField, this
+ else
+ @context.binds @content, "change", @setField, this
def setContent: () ->
@content.val @fieldValue()
def setField: () ->
- @field.set @content.val()
+ if _.isArray @field
+ @model.writePath @field, @content.val()
+ else
+ @field.set @content.val()
View
6 lib/alpha_simprini/client/binding/model.coffee
@@ -16,8 +16,7 @@ AS.Binding.Model = AS.Object.extend ({def}) ->
value = @styles[property]()
@content.css property, value
- bindingPath = AS.deepClone(options)
- bindingPath[options.length - 1] = "change:#{_(options).last()}"
+ bindingPath = options
@context.binds @model, bindingPath, painter, this
else
@styles[property] = => options.fn(@model)
@@ -41,8 +40,7 @@ AS.Binding.Model = AS.Object.extend ({def}) ->
painter = => _.defer =>
@content.attr property, @attrs[property]()
- bindingPath = AS.deepClone(options)
- bindingPath[options.length - 1] = "change:#{_(options).last()}"
+ bindingPath = options
@context.binds @model, bindingPath, painter, this
else
@attrs[property] = =>
View
6 lib/alpha_simprini/client/binding/select.coffee
@@ -23,7 +23,9 @@ AS.Binding.Select = AS.Binding.Input.extend ({def}) ->
def setField: ->
value = @select.val()
- if _.isArray value
- @field.set value[0]
+ value = if _.isArray value then value[0] else value
+
+ if _.isArray @field
+ @model.writePath @field, value
else
@field.set value
View
5 lib/alpha_simprini/client/binding_group.coffee
@@ -16,8 +16,11 @@ AS.BindingGroup = AS.Object.extend ({def}) ->
def binds: (object, event, handler, context) ->
@boundObjects.push object
+
if object.jquery
- object.bind "#{event}.#{@namespace}", handler
+ object.bind "#{event}.#{@namespace}", _.bind(handler, context)
+ else if _.isArray(event)
+ object.bindPath(event, _.bind(handler, context))
else
object.bind
event: event
View
22 lib/alpha_simprini/client/view.coffee
@@ -5,12 +5,17 @@ fleck = require("fleck")
AS.View = AS.DOM.extend ({delegate, include, def, defs}) ->
include Taxi.Mixin
+ include AS.Callbacks
+
+ @defineCallbacks after: ['content'], before: ['content']
delegate 'addClass', 'removeClass', 'show', 'hide', 'html', to: "el"
def tagName: "div"
- def _ensureElement: -> @el ?= @$(@buildElement())
+ def _ensureElement: ->
+ @el ?= @$(@buildElement())
+ @el.data().view = this
def initialize: (config={}) ->
config.el = @$(config.el) if config.el and !(config.el.jquery)
@@ -28,7 +33,14 @@ AS.View = AS.DOM.extend ({delegate, include, def, defs}) ->
@currentNode = @el[0]
@childViews = []
+
+ @runCallbacks "beforeContent"
+ @content()
@delegateEvents()
+ @runCallbacks "afterContent"
+
+ def content: ->
+ # Make your content here.
def append: (view) -> @el.append view.el
@@ -94,11 +106,11 @@ AS.View = AS.DOM.extend ({delegate, include, def, defs}) ->
@parentView.removeChild(this)
@el.remove()
- def binding: (bindable, fnOrElement) ->
- if bindable instanceof AS.Collection
- AS.Binding.Many.new(this, bindable, bindable, fnOrElement)
+ def binding: (bindable, options, fnOrElement) ->
+ if bindable instanceof AS.Collection or bindable instanceof AS.Model.HasMany.Instance
+ AS.Binding.Many.new(this, bindable, bindable, options, fnOrElement)
else if bindable instanceof AS.Model
- AS.Binding.Model.new(this, bindable, fnOrElement)
+ AS.Binding.Model.new(this, bindable, options or fnOrElement)
def delegateEvents: () ->
if @events
View
13 lib/alpha_simprini/client/view_model.coffee
@@ -32,6 +32,9 @@ AS.ViewModel = AS.Object.extend ({def, defs}) ->
for method in AS.instanceMethods(model)
continue if _.include _.keys(Pathology.Object::), method
do (method) =>
+ # FIXME: shouldn't be checking for specific conflicting methods here.
+ if method is 'select'
+ klass::[method] = -> @model[method].apply(@model, arguments)
klass::[method] ?= -> @model[method].apply(@model, arguments)
return klass
@@ -48,13 +51,13 @@ AS.ViewModel = AS.Object.extend ({def, defs}) ->
@constructor.bindables[field].new(@view, @model, @model[field], options, fn)
def input: (field, options) ->
- AS.Binding.Input.new(@view, @model, @model[field], options)
+ AS.Binding.Input.new(@view, @model, field, options)
def checkbox: (field, options) ->
- AS.Binding.CheckBox.new(@view, @model, @model[field], options)
+ AS.Binding.CheckBox.new(@view, @model, field, options)
- # def select: (field, options) ->
- # AS.Binding.Select.new(@view, @model, @model[field], options)
+ def select: (field, options) ->
+ AS.Binding.Select.new(@view, @model, field, options)
def editline: (field, options) ->
- AS.Binding.EditLine.new(@view, @model, @model[field], options)
+ AS.Binding.EditLine.new(@view, @model, field, options)
View
3 lib/alpha_simprini/client/views/dialog.coffee
@@ -16,7 +16,8 @@ AS.Views.Dialog = AS.Views.Panel.extend ({delegate, include, def, defs}) ->
"knead:dragend header": "dragend"
@_super.apply(this, arguments)
-
+
+ def content: ->
@head = @$ @header @header_content
@content = @$ @section @main_content
@foot = @$ @footer @footer_content
View
2 lib/alpha_simprini/client/views/horizontal_split.coffee
@@ -1,7 +1,7 @@
module "AS.Views", ->
class @HorizontalSplit extends AS.View
- initialize: (args) ->
+ content: (args) ->
@left ?= new AS.Views.Panel
@bar ?= new AS.Views.Splitter
@right ?= new AS.Views.Panel
View
6 lib/alpha_simprini/core/callbacks.coffee
@@ -1,12 +1,14 @@
AS = require("alpha_simprini")
+{upperCamelize} = require("fleck")
+
AS.Callbacks = AS.Module.extend ({def, defs}) ->
defs defineCallbacks: (all) ->
for key, callbacks of all
do (key, callbacks) =>
for callback in callbacks or []
do (callback) =>
- @["#{key}_#{callback}"] = (fn) ->
- @pushInheritableItem("#{key}_#{callback}_callbacks", fn)
+ @["#{key}#{upperCamelize callback}"] = (fn) ->
+ @pushInheritableItem("#{key}#{upperCamelize callback}_callbacks", fn)
def runCallbacks: (name) ->
for callback in @constructor["#{name}_callbacks"] || []
View
12 lib/alpha_simprini/core/collection.coffee
@@ -38,11 +38,13 @@ AS.Collection = AS.Object.extend ({def, include, delegate}) ->
if model.id and AS.All.byId[model.id]
return AS.All.byId[model.id]
else if model._type
- ctor = AS.module(model._type)
+ ctor = AS.loadPath(model._type)
else
ctor = @model()
-
- ctor.new(model)
+
+ data = _.clone(model)
+ delete data._type
+ ctor.new(data)
def _add: (model, options={}) ->
options.at ?= this.length
@@ -81,8 +83,8 @@ AS.Collection = AS.Object.extend ({def, include, delegate}) ->
event: "all"
namespace: @objectId()
- def filter: (fn) ->
- AS.FilteredCollection.new(this, fn)
+ def filter: (filterBy) ->
+ AS.FilteredCollection.new(this, filterBy)
def groupBy: (key, metaData) ->
AS.Models.Grouping.new(this, key, metaData)
View
36 lib/alpha_simprini/core/filtered_collection.coffee
@@ -12,16 +12,19 @@
# add: ->
# remove: ->
AS = require "alpha_simprini"
-{extend, isString} = require "underscore"
+Taxi = require "taxi"
+{extend, isString, isFunction, isArray} = require "underscore"
AS.FilteredCollection = AS.Collection.extend ({delegate, include, def, defs}) ->
delegate 'add', 'remove', to: 'parent'
- @property 'filter'
- def initialize: (@parent, filter=(-> true)) ->
+ def initialize: (@parent, conditions={}) ->
@_super()
- @filter.bind
+ @conditions = Taxi.Map.new()
+ @conditions.set(key, value) for key, value of conditions
+
+ @conditions.bind
event: 'change'
handler: @reFilter
context: this
@@ -44,10 +47,10 @@ AS.FilteredCollection = AS.Collection.extend ({delegate, include, def, defs}) ->
context: this
namespace: @objectId()
- @filter.set(filter)
+ @reFilter()
def determinePlacementInSelf: (model) ->
- if @filter.get()(model) is true
+ if @filter(model) is true
@addToSelf(model)
else
@removeFromSelf(model)
@@ -59,11 +62,28 @@ AS.FilteredCollection = AS.Collection.extend ({delegate, include, def, defs}) ->
def removeFromSelf: (model) ->
return unless @models.include(model).value()
@_remove(model)
- # # FIXME: thish should trigger on the previous method
- # @trigger("remove", model)
def reFilter: ->
@parent.each (model) => @determinePlacementInSelf(model)
+ def setConditions: (conditions) ->
+ @conditions.unbind()
+ @conditions.set(key, value) for key, value of conditions
+ @conditions.bind
+ event: 'change'
+ handler: @reFilter
+ context: this
+ @reFilter()
+
+ def filter: (model) ->
+ for key, value of @conditions.toObject()
+ modelValue = model[key].get()
+ testValue = if isFunction(value) then value.call() else value
+ testValue = if isArray(testValue) then testValue else [testValue]
+
+ return false unless modelValue in testValue
+
+ true
+
View
1 lib/alpha_simprini/core/model.coffee
@@ -18,6 +18,7 @@ AS.Model = AS.Object.extend ({def, include}) ->
def set: (attributes) ->
for key, value of attributes
+ continue if key is "_type"
if key is "id"
@setId(value)
else
View
6 lib/alpha_simprini/core/model/dendrite.coffee
@@ -33,8 +33,10 @@ AS.Model.CollectionDendrite = AS.Model.Dendrite.extend ({delegate, include, def,
def on: ->
@notifier.binds @insertCallback, @removeCallback
- @notifier.each (item, index) =>
- @insertCallback(item, index)
+
+ if @config.syncNow
+ @notifier.each (item, index) =>
+ @insertCallback(item, index)
def off: ->
@notifier.unbinds @insertCallback, @removeCallback
View
16 lib/alpha_simprini/core/model/rest.coffee
@@ -1,5 +1,5 @@
AS = require "alpha_simprini"
-{camelize, underscore, pluralize} = require "fleck"
+{camelize, underscore, pluralize, singularize} = require "fleck"
_ = require "underscore"
$ = require "jquery"
@@ -95,15 +95,21 @@ AS.Model.REST = AS.Module.extend ({delegate, include, def, defs}) ->
for key, references of ids
continue unless references
- relationKey = key.replace(/Id/, '')
- path = @[relationKey].model().path()
-
if references.length is undefined
+ relationKey = key.replace(/Id$/, '')
+ path = @[relationKey].model().path()
id = references
@[relationKey].set AS.All.byIdRef["#{id}-#{path}"]
else
+ relationKey = pluralize key.replace(/Ids$/, '')
+ path = @[relationKey].model().path()
for id in references
- @[relationKey].add AS.All.byIdRef["#{id}-#{path}"]
+ item = AS.All.byIdRef["#{id}-#{path}"]
+ relation = @[relationKey]
+
+ # careful not to double-add at load time
+ continue if relation.include(item).value()
+ relation.add(item)
View
21 lib/alpha_simprini/core/model/share.coffee
@@ -1,29 +1,30 @@
AS = require "alpha_simprini"
_ = require "underscore"
+ShareJs = require("share").client
AS.ShareJsURL = "http://#{window?.location.host or 'localhost'}/sjs"
AS.openSharedObject = (id, callback) ->
- @share.open id, "json", @ShareJsURL, (error, handle) ->
+ ShareJs.open id, "json", @ShareJsURL, (error, handle) ->
if error then console.log(error) else callback(handle)
AS.Model.Share = AS.Module.extend ({delegate, include, def, defs}) ->
defs index: (name, config) ->
@writeInheritableValue 'indeces', name, config
- defs shared: (id=AS.uniq(), indexer=(model) -> model.didIndex()) ->
+ defs shared: (id=AS.uniq(), indexer=(model) -> ) ->
model = AS.All.byId[id] or @new(id:id)
AS.openSharedObject id, (share) ->
model.didOpen(share)
indexer(model)
model
defs load: (id, callback) ->
- unless model = AS.All.byId[id]
- model = @new(id:id)
- callback ?= model.didLoad
- AS.openSharedObject id, _.bind(callback, model)
+ model = AS.All.byId[id] or @new(id:id)
+ AS.openSharedObject id, (share) ->
+ model.didLoad(share)
+ callback.call(model)
model
def new: ->
@@ -56,6 +57,7 @@ AS.Model.Share = AS.Module.extend ({delegate, include, def, defs}) ->
@share.at().set({_type: @constructor.toString(), id:@id})
@bindShareEvents()
@buildIndeces()
+ @loadIndeces()
def indeces: ->
@index(name) for name, config of @constructor.indeces
@@ -68,11 +70,11 @@ AS.Model.Share = AS.Module.extend ({delegate, include, def, defs}) ->
@[name] for name, config of @constructor.properties
def bindShareEvents: ->
- property?.syncWith?(@share) for property in @properties()
+ for property in @properties()
+ property?.syncWith?(@share)
for index in @indeces()
index.on "insert", (id, konstructor) =>
loaded = AS.loadPath(konstructor).load id, (share) ->
- @didLoad(share)
@indecesDidLoad()
@trigger("indexload", loaded)
@@ -99,8 +101,7 @@ AS.Model.Share = AS.Module.extend ({delegate, include, def, defs}) ->
loadedItem = _.after count, callback
for id, _type of specs
model = AS.loadPath(_type).load(id, loadedItem)
- model.bind "destroy", =>
- index.at(id).remove()
+ model.bind "destroy", => index.at(id).remove()
def indecesDidLoad: ->
unless @hasIndexed
View
6 lib/alpha_simprini/core/model/synapse.coffee
@@ -13,10 +13,12 @@ AS.Model.AbstractSynapse = AS.Object.extend ({delegate, include, def, defs}) ->
@observations = []
@notifications = []
- def observe: (other, config) ->
+ def observe: (other, config={}) ->
+ config.syncNow = true
@observations.push @dendriteClass.new(this, other, config)
- def notify: (other, config) ->
+ def notify: (other, config={}) ->
+ config.syncNow = false
@notifications.push @dendriteClass.new(other, this, config)
def stopObserving: (other) ->
View
4 lib/alpha_simprini/core/properties/embeds_many.coffee
@@ -8,8 +8,8 @@ AS.Model.EmbedsMany.Instance = AS.Model.HasMany.Instance.extend ({def, delegate}
if @share.get() in [null, undefined]
@share.set([])
@each (item, index) => item.didEmbed @share.at(index)
- else
- _.each @share.get(), (item, index) => @add(item)
+ # else
+ # _.each @share.get(), (item, index) => @add(item)
def add: (item, options={}) ->
item = @backingCollection.add.apply(@backingCollection, arguments)
View
4 lib/alpha_simprini/core/properties/embeds_one.coffee
@@ -4,11 +4,13 @@ AS.Model.EmbedsOne = AS.Model.HasOne.extend()
AS.Model.EmbedsOne.Instance = AS.Model.HasOne.Instance.extend ({delegate, include, def, defs}) ->
def syncWith: (share) ->
@share = share.at(@options.name)
+ @set @share.get() if @share.get()
def set: (value) ->
@value.stopSync() if @value
- value.didEmbed(@share) unless value in [@value, undefined, null]
@_super.apply(this, arguments)
+ @value.didEmbed(@share) if @share# unless value in [@value, undefined, null]
+ @value
AS.Model.defs embedsOne: (name, options) ->
AS.Model.EmbedsOne.new(name, this, options)
View
77 lib/alpha_simprini/core/properties/field.coffee
@@ -3,37 +3,51 @@ _ = require("underscore")
{isBoolean, isString} = require "underscore"
# TODO: Field is generic. reuse it.
+
+AS.Enum = AS.Object.extend ({delegate, include, def, defs}) ->
+ defs read: (value, options) ->
+ # AS.Assert options.values
+ options.values[value]
+
+ defs write: (value, options) ->
+ # AS.Assert options.values
+ options.values.indexOf(value)
+
AS.Model.Field = AS.Property.extend ({delegate, include, def, defs}) ->
- defs Casters:
- String:
- read: String
- write: String
-
- Number:
- read: Number
- write: Number
-
- Date:
- read: (value) ->
- if isString(value) then new Date(value) else value
-
- write: (value) ->
- if value instanceof Date then value.toJSON() else value
-
- Boolean:
- read: (value) ->
- return value if isBoolean(value)
- return true if value is "true"
- return false if value is "false"
- return false
-
- write: (value) ->
- return "true" if value is "true" or value is true
- return "false" if value is "false" or value is false
- return "false"
+ defs Casters: AS.Map.new()
Casters = @Casters
+ Casters.set String,
+ read: String
+ write: String
+
+ Casters.set Number,
+ read: Number
+ write: Number
+
+ Casters.set Date,
+ read: (value) ->
+ if isString(value) then new Date(value) else value
+
+ write: (value) ->
+ if value instanceof Date then value.toJSON() else value
+
+ Casters.set Boolean,
+ read: (value) ->
+ return value if isBoolean(value)
+ return true if value is "true"
+ return false if value is "false"
+ return false
+
+ write: (value) ->
+ return "true" if value is "true" or value is true
+ return "false" if value is "false" or value is false
+ return "false"
+
+ Casters.set AS.Enum, AS.Enum
+
+
def initialize: (@name, @_constructor, @options={}) ->
@options.name = @name
@_constructor.writeInheritableValue 'properties', @name, this
@@ -45,6 +59,7 @@ AS.Model.Field = AS.Property.extend ({delegate, include, def, defs}) ->
@options.type ?= String
def syncWith: (share) ->
+ @share = share.at(@options.name)
@stopSync()
@synapse = @constructor.Synapse.new(this)
@@ -59,18 +74,18 @@ AS.Model.Field = AS.Property.extend ({delegate, include, def, defs}) ->
def get: ->
if @value isnt undefined
- value = Casters[@options.type.name].read(@value)
+ value = Casters.get(@options.type).read(@value, @options)
else
@options.default
def set: (value) ->
- writeValue = Casters[@options.type.name].write(value)
- return if writeValue is @value
+ writeValue = Casters.get(@options.type).write(value, @options)
+ return @value if writeValue is @value
@value = writeValue
@object.trigger("change")
@object.trigger("change:#{@options.name}")
@trigger("change")
- value
+ @value
@Synapse = AS.Model.Synapse.extend ({delegate, include, def, defs}) ->
delegate 'get', 'set', to: 'raw'
View
24 lib/alpha_simprini/core/properties/has_many.coffee
@@ -3,18 +3,39 @@ _ = require("underscore")
AS.Model.HasMany = AS.Model.Field.extend ({delegate, include, def, defs}) ->
def couldBe: (test) ->
- return true if test in (@options.model?()?.ancestors ? [])
+ return true if @options.model?() in (test.ancestors or [])
@_super.apply(this, arguments)
AS.Model.HasMany.Instance = AS.Model.Field.Instance.extend ({def, delegate}) ->
delegate AS.COLLECTION_DELEGATES, to: "backingCollection"
delegate 'groupBy', to: "backingCollection"
+ def inspect: ->
+ "#{@options.name}: [#{@backingCollection.length}]}"
+
def initialize: (@object, @options={}) ->
@model = @options.model
@options.source = @object if @options.inverse
@backingCollection = AS.Collection.new(undefined, @options)
+ def syncWith: (share) ->
+ @share = share.at(@options.name)
+ @stopSync()
+
+ @synapse = @constructor.Synapse.new(this)
+ @shareSynapse = @constructor.ShareSynapse.new(share, @options.name)
+
+ alreadyThere = _.clone @backingCollection.models.value()
+
+ @synapse.observe(@shareSynapse, field: @options.name)
+
+ _.each alreadyThere, (item) => @shareSynapse.insert(item, {})
+
+ @synapse.notify(@shareSynapse)
+
+ def objects: ->
+ @backingCollection.models.value()
+
def bindToPathSegment: (segment) ->
segment.binds this, "add", segment.insertCallback
segment.binds this, "remove", segment.removeCallback
@@ -75,6 +96,7 @@ AS.Model.HasMany.Instance = AS.Model.Field.Instance.extend ({def, delegate}) ->
@raw.removeListener(listener) for listener in @listeners
def insert: (model, options) ->
+ options.at ?= @raw.at(@path).get().length
@raw.at(@path).insert(options.at, id: model.id, _type: model.constructor.path())
def remove: (model, options) ->
View
14 lib/alpha_simprini/core/properties/has_one.coffee
@@ -19,7 +19,7 @@ AS.Model.HasOne.Instance = AS.Model.Field.Instance.extend ({def}) ->
def set: (value) ->
value = value.model if value?.model
- return if value is @value
+ return @value if value is @value
if _.isString(value)
value = AS.All.byId[value]
@@ -31,19 +31,21 @@ AS.Model.HasOne.Instance = AS.Model.Field.Instance.extend ({def}) ->
@value?.unbind(@namespace)
# TODO: test inverse
- if @value and @options.inverse and @object[@options.inverse]
- @value[@options.inverse].remove(@object)
+
+ if @value and @options.inverse and @value[@options.inverse]
+ @value[@options.inverse].remove(@object) if @value[@options.inverse].include(@object).value()
@value = value
- if @value and @options.inverse and @object[@options.inverse]
- @value[@options.inverse].add(@object)
+ if @value and @options.inverse and @value[@options.inverse]
+ debugger if window.DEBUG
+ @value[@options.inverse].add(@object) unless @value[@options.inverse].include(@object).value()
@value?.bind "all#{@namespace}", _.bind(@trigger, this)
@object.trigger("change")
@object.trigger("change:#{@options.name}")
@trigger("change")
- value
+ @value
@Synapse = AS.Model.Field.Instance.Synapse.extend ({delegate, include, def, defs}) ->
def get: ->
View
15 test/core/filtered_collection.coffee
@@ -35,7 +35,7 @@ exports.FilteredCollection =
"respects filter function when adding models": (test) ->
c = C.Collection.new()
- f = c.filter (model) -> model.truth.get() is false
+ f = c.filter truth: false
one = c.add C.Model.new()
two = c.add C.Model.new(truth: true)
@@ -46,7 +46,7 @@ exports.FilteredCollection =
"add filtered items when they change": (test) ->
c = C.Collection.new()
- f = c.filter (model) -> model.truth.get() is false
+ f = c.filter truth: false
one = c.add C.Model.new()
two = c.add C.Model.new(truth: true)
@@ -58,7 +58,7 @@ exports.FilteredCollection =
"remove filtered items when they change": (test) ->
c = C.Collection.new()
- f = c.filter (model) -> model.truth.get() is false
+ f = c.filter truth: false
one = c.add C.Model.new()
two = c.add C.Model.new()
@@ -73,7 +73,7 @@ exports.FilteredCollection =
test.expect 5
c = C.Collection.new()
- f = c.filter (model) -> model.truth.get() is false
+ f = c.filter truth: false
f.bind "add", (model) -> test.ok(model)
f.bind "remove", (model) -> test.ok(model)
@@ -88,17 +88,18 @@ exports.FilteredCollection =
test.deepEqual [one, three], f.models.value()
test.done()
- "re-filters when fn changes": (test) ->
+ "re-filters when filter changes": (test) ->
c = C.Collection.new()
- f = c.filter (model) -> model.truth.get() is false
+ f = c.filter truth: false
one = c.add C.Model.new()
two = c.add C.Model.new(truth: true)
three = c.add C.Model.new()
- f.filter.set (model) -> model.truth.get() is true
+ f.setConditions(truth: true)
test.deepEqual [two], f.models.value()
test.done()
+
View
14 test/core/properties/field.coffee
@@ -7,6 +7,7 @@ Model.field "name"
Model.field "band", default: "the Tijuana Brass"
Model.field "number", type: Number
Model.field "boolean", type: Boolean
+Model.field "enum", type: AS.Enum, values: ["zero", "one", "two"]
Model.property "other"
exports.Field =
@@ -53,6 +54,19 @@ exports.Field =
o.number.set 43
test.done()
+ "Enum":
+ "reads enums": (test) ->
+ o = Model.new()
+ o.enum.value = 0
+ test.equal o.enum.get(), "zero"
+ test.done()
+
+ "writes enums": (test) ->
+ o = Model.new()
+ o.enum.set("two")
+ test.equal 2, o.enum.value
+ test.done()
+
"bindPath":
"may be used in path bindings": (test) ->
o = Model.new()
View
29 test/core/properties/has_many.coffee
@@ -62,6 +62,35 @@ exports.HasMany =
test.done()
"Sharing":
+ "on load":
+ "loads objects from share": (test) ->
+ shareData =
+ children: [
+ {_type: "NS.Child", id: _.uniqueId()}
+ {_type: "NS.Child", id: _.uniqueId()}
+ ]
+
+ share = makeDoc(null, shareData)
+ o = NS.Parent.new()
+ o.children.syncWith(share)
+ test.equal 2, o.children.backingCollection.length
+
+ test.done()
+
+ "doesn't re-add data to share": (test) ->
+ shareData =
+ children: [
+ {_type: "NS.Child", id: _.uniqueId()}
+ {_type: "NS.Child", id: _.uniqueId()}
+ ]
+
+ share = makeDoc(null, shareData)
+ o = NS.Parent.new()
+ o.children.syncWith(share)
+ test.equal 2, share.at('children').get().length
+
+ test.done()
+
"propagate values from model to share on sync": (test) ->
o = NS.Parent.new()
child = NS.Child.new()

0 comments on commit 60cc30f

Please sign in to comment.
Something went wrong with that request. Please try again.