Permalink
Browse files

deleted EmbedsOne/EmbedsMany

  • Loading branch information...
1 parent 1e31fe1 commit 47bacfa6cedc2096f45b110fed32e40d992e151b @collin committed Apr 24, 2012
@@ -39,51 +39,3 @@ AS.Binding = AS.Object.extend ({def}) ->
def setup: ->
class AS.Binding.MissingOption extends Error
-
-# class AS.Binding.EmbedsMany extends AS.Binding.HasMany
-# class AS.Binding.EmbedsOne extends AS.Binding.Field
-# @willGroupBindings = true
-
-# class AS.Binding.HasOne extends AS.Binding.Field
-# @willGroupBindings = true
-
-# class AS.Binding.Many extends AS.Binding.HasMany
-# fieldValue: -> @model
-
-# # use case: RadioSelectionModel
-# # ala-BAM-a
-# # @element_focus.binding "selected", (element) ->
-# # new Author.Views.ElementBoxAS.Binding(this, @div class:"Focus", element)
-# #
-# # @element_selection.binding "selected", (element) ->
-# # new Author.Views.ElementBoxBinding(this, @div class:"Selection", element)
-
-# class AS.Binding.BelongsTo extends AS.Binding
-# @willGroupBindings = true
-
-# initialize: ->
-# @makeContent()
-# @context.withinBindingGroup @bindingGroup, ->
-# @context.binds @model, @event, @changed, this
-
-# changed: ->
-# @content.remove()
-# @bindingGroup.unbind()
-# @initialize()
-
-# makeContent: ->
-# item = @fieldValue()
-# if item
-# @context.withinBindingGroup @bindingGroup, ->
-# @context.withinNode @container, ->
-# @content = @context.$ []
-# binding = new AS.Binding.Model(@context, item, @content)
-# made = @fn.call(@context, AS.ViewModel.build(@context, item), binding)
-# if made?.jquery
-# @content.push made[0]
-# else
-# @content.push made
-# binding.paint()
-# @content
-# else
-# @content = @context.$ []
@@ -25,9 +25,9 @@ AS.ViewModel = AS.Object.extend ({delegate, include, def, defs}) ->
klass.bindables[name] = switch property.constructor
when AS.Model.Field, Pathology.Property, Taxi.Property, AS.Model.VirtualProperty
AS.Binding.Field
- when AS.Model.BelongsTo, AS.Model.EmbedsOne, AS.Model.HasOne
+ when AS.Model.BelongsTo, AS.Model.HasOne
AS.Binding.One
- when AS.Model.HasMany, AS.Model.EmbedsMany
+ when AS.Model.HasMany
AS.Binding.Many
for method in AS.instanceMethods(model)
@@ -1,34 +0,0 @@
-AS = require "alpha_simprini"
-_ = require "underscore"
-
-AS.Model.EmbedsMany = AS.Model.HasMany.extend()
-AS.Model.EmbedsMany.Instance = AS.Model.HasMany.Instance.extend ({def, delegate}) ->
- def syncWith: (share) ->
- @share = share.at(@options.name)
- if @share.get() in [null, undefined]
- @share.set([])
- @each (item, index) => item.didEmbed @share.at(index)
- else
- _.each @share.get(), (item, index) =>
- @add(item)
-
- def add: (item, options={}) ->
- console.log "add" if item instanceof Pasteup.Models.StyleComponent
- # console.warn "wrapping EmbedsMany add in a try"
- try
- item = @backingCollection.add.apply(@backingCollection, arguments)
- @triggerDependants()
- options.at ?= @backingCollection.length - 1
- item.didEmbed @share.at(options.at) if @share
- return item
-
- def remove: (item) ->
- index = @backingCollection.indexOf(item).value()
- @triggerDependants()
- @backingCollection.remove.apply(@backingCollection, arguments)
- @share.at(index).remove() if @share
- item.stopSync()
- return item
-
-AS.Model.defs embedsMany: (name, options) ->
- AS.Model.EmbedsMany.new(name, this, options)
@@ -1,16 +0,0 @@
-AS = require "alpha_simprini"
-
-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
- @_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)
@@ -28,16 +28,6 @@ exports.Binding =
# test.equal binding.pathValue(), binding.model
# test.done()
- # EmbedsMany:
- # "extends AS.Binding.HasMany": (test) ->
- # test.equal AS.Binding.EmbedsMany.__super__.constructor, AS.Binding.HasMany
- # test.done()
-
- # EmbedsOne:
- # "extends AS.Binding.Field": (test) ->
- # test.equal AS.Binding.EmbedsOne.__super__.constructor, AS.Binding.Field
- # test.done()
-
# HasOne:
# "extends AS.Binding.Field": (test) ->
# test.equal AS.Binding.HasOne.__super__.constructor, AS.Binding.Field
@@ -8,17 +8,13 @@ Rested = NS.Rested = AS.Model.extend ({delegate, include, def, defs}) ->
@field "field"
@field "thingId"
@field "thingType"
- # @embedsMany "embeds", model: -> SimpleRest
- # @embedsOne "embedded", model: -> SimpleRest
@hasMany "relations", model: -> SimpleRest
# @hasOne "relation"
@belongsTo "owner", model: -> SimpleRest
SimpleRest = NS.SimpleRest = AS.Model.extend ({delegate, include, def, defs}) ->
include AS.Model.REST
@field "field"
- # @embedsMany "embeds", model: -> SimplerRest
- # @embedsOne "embedded", model: -> SimplerRest
@hasMany "relations", model: -> SimplerRest
# @hasOne "relation"
@belongsTo "owner", model: -> SimplerRest
@@ -4,17 +4,13 @@ exports.setUp = coreSetUp
Shared = NS.Shared = AS.Model.extend ({delegate, include, def, defs}) ->
include AS.Model.Share
@field "field"
- @embedsMany "embeds", model: -> SimpleShare
- @embedsOne "embedded", model: -> SimpleShare
@hasMany "relations", model: -> SimpleShare
# @hasOne "relation"
@belongsTo "owner"
SimpleShare = NS.SimpleShare = AS.Model.extend ({delegate, include, def, defs}) ->
include AS.Model.Share
@field "field"
- @embedsMany "embeds", model: -> SimplerShare
- @embedsOne "embedded", model: -> SimplerShare
@hasMany "relations", model: -> SimplerShare
# @hasOne "relation"
@belongsTo "owner"
@@ -175,7 +171,7 @@ exports["Share Integration"] =
NS.Embed = AS.Model.extend ({delegate, include, def, defs}) ->
include AS.Model.Share
- @embedsMany 'embeds'
+ @hasMany 'embeds'
callback()
@@ -1,72 +0,0 @@
-helper = require require("path").resolve("./test/helper")
-{AS, _, sinon, makeDoc, coreSetUp, RelationModel, FieldModel, NS} = helper
-exports.setUp = coreSetUp
-
-NS.Parent = AS.Model.extend()
-NS.Parent.embedsMany "embeds", model: -> NS.Child
-NS.Parent.include AS.Model.Share
-
-NS.Child = AS.Model.extend()
-NS.Child.include AS.Model.Share
-
-exports.EmbedsMany =
- "property is a HasMany": (test) ->
- o = NS.Parent.new()
- test.ok o.embeds instanceof AS.Model.HasMany.Instance
- test.done()
-
- "property is an EmbedsMany": (test) ->
- o = NS.Parent.new()
- test.ok o.embeds instanceof AS.Model.EmbedsMany.Instance
- test.done()
-
- Sharing:
- "on sync":
- "propagates value from field to share": (test) ->
- o = NS.Parent.new()
- child = NS.Child.new()
- o.embeds.add(child)
- share = makeDoc()
- share.at().set({})
- o.embeds.syncWith(share)
-
- test.deepEqual [{_type: "NS.Child", id:child.id}], share.at('embeds').get()
- test.done()
-
- "propagates value from share to field": (test) ->
- o = NS.Parent.new()
- child = NS.Child.new()
- share = makeDoc()
- share.at().set embeds: [{_type: "NS.Child", id:child.id}]
- o.embeds.syncWith(share)
- test.equal child.toString(), o.embeds.backingCollection.at(0).toString()
- test.done()
-
- setUp: (callback) ->
- @o = NS.Parent.new()
- @share = makeDoc()
- @share.at().set {}
- @o.embeds.syncWith(@share)
- callback()
-
- "stashes @share with path": (test) ->
- test.deepEqual ['embeds'], @o.embeds.share.path
- test.done()
-
- "default share value is []": (test) ->
- test.deepEqual [], @share.at('embeds').get()
- test.done()
-
- "calls didEmbed on models as they are inserted": (test) ->
- child = NS.Child.new()
- child.didEmbed = (share) ->
- test.deepEqual ['embeds', 0], share.path
- test.done()
- @o.embeds.add(child)
-
- "calls stopSync on models as they are removed": (test) ->
- child = NS.Child.new()
- child.stopSync = -> test.done()
- @o.embeds.add(child)
- @o.embeds.remove(child)
-
@@ -1,50 +0,0 @@
-helper = require require("path").resolve("./test/helper")
-{AS, _, sinon, makeDoc, coreSetUp, RelationModel, FieldModel, NS} = helper
-exports.setUp = coreSetUp
-
-NS.Parent = AS.Model.extend()
-NS.Parent.embedsOne "embed"
-
-NS.Child = NS.Parent.extend ->
- @include AS.Model.Share
- @field "name"
-
-exports.EmbedsOne =
- "property is a HasOne": (test) ->
- o = NS.Parent.new()
- test.ok o.embed instanceof AS.Model.HasOne.Instance
- test.done()
-
- "property is an EmbedsOne": (test) ->
- o = NS.Parent.new()
- test.ok o.embed instanceof AS.Model.EmbedsOne.Instance
- test.done()
-
- "Sharing":
- setUp: (callback) ->
- @o = NS.Parent.new()
- @share = makeDoc()
- @share.at().set {}
- @o.embed.syncWith(@share)
- callback()
-
- "stashes @share with path": (test) ->
- test.deepEqual ['embed'], @o.embed.share.path
- test.done()
-
- "default value is null": (test) ->
- test.equal null, @o.embed.get()
- test.done()
-
- "syncs model with @share when value is set": (test) ->
- child = NS.Child.new()
- @o.embed.set(child)
- test.deepEqual @share.at("embed"), child.share
- test.done()
-
- "stops syncing model whith @share when value is re-set": (test) ->
- child = NS.Child.new()
- child.stopSync = -> test.done()
- child2 = NS.Child.new()
- @o.embed.set(child)
- @o.embed.set(child2)

0 comments on commit 47bacfa

Please sign in to comment.