Skip to content

Commit

Permalink
internal application boots/renders
Browse files Browse the repository at this point in the history
  • Loading branch information
collin committed Apr 1, 2012
1 parent 1649ff9 commit 4e17d2d
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 165 deletions.
2 changes: 1 addition & 1 deletion lib/alpha_simprini/client/binding.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AS.Binding.MissingOption extends Error
# class AS.Binding.HasOne extends AS.Binding.Field
# @willGroupBindings = true

# class AS.Binding.Collection extends AS.Binding.HasMany
# class AS.Binding.Many extends AS.Binding.HasMany
# fieldValue: -> @model

# # use case: RadioSelectionModel
Expand Down
6 changes: 1 addition & 5 deletions lib/alpha_simprini/client/dom.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ SVG_ELEMENTS = _('
font-face-name definition-src foreignObject
'.split(" ")).chain().compact()

AS.DOM = AS.Object.extend ({def}) ->

# def constructor: (args) ->
# # body...

AS.DOM = AS.Object.extend ({delegate, include, def, defs}) ->
def $: $

def text: (textContent) ->
Expand Down
14 changes: 12 additions & 2 deletions lib/alpha_simprini/client/view.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
AS = require("alpha_simprini")
Taxi = require("taxi")
_ = require("underscore")
fleck = require("fleck")

AS.View = AS.DOM.extend ({def}) ->
AS.View = AS.DOM.extend ({delegate, include, def, defs}) ->
include Taxi.Mixin

def tagName: "div"

def _ensureElement: -> @el ?= @$(@buildElement())
Expand Down Expand Up @@ -44,7 +47,14 @@ AS.View = AS.DOM.extend ({def}) ->

def binds: -> @bindingGroup.binds.apply(@bindingGroup, arguments)

def klassString: -> @constructor.path().replace /\./g, " "
def klassString: ->
classes = []
for ancestor in @constructor.ancestors
continue unless ancestor.path().match(/Views?/)
classes.push ancestor._name()

classes.join(" ")


def baseAttributes: ->
attrs =
Expand Down
11 changes: 7 additions & 4 deletions lib/alpha_simprini/client/view_model.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ AS.ViewModel = AS.Object.extend ({def, defs}) ->
klass.extended_by = model.extended_by

for name, property of model.properties
console.log property.constructor.toString() if name is "selected"
klass.bindables[name] = switch property.constructor
when AS.Model.Field
when AS.Model.Field, AS.Model.BelongsTo, AS.Model.EmbedsOne, AS.Model.HasOne
AS.Binding.Field
when AS.Model.HasMany
when AS.Model.HasMany, AS.Model.EmbedsMany
AS.Binding.Many
when AS.Model.HasOne
AS.Binding.HasOne
# when AS.Model.HasOne
# AS.Binding.HasOne

for method in AS.instanceMethods(model)
continue if _.include _.keys(Pathology.Object::), method
Expand All @@ -37,6 +38,8 @@ AS.ViewModel = AS.Object.extend ({def, defs}) ->

def initialize: (@view, @model) ->
@cid = @model.cid
for key, config of @model.constructor.properties
@[key] = @model[key]

def binding: (field, options, fn) ->
if _.isFunction(options)
Expand Down
2 changes: 1 addition & 1 deletion lib/alpha_simprini/client/views/stage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ AS = require "alpha_simprini"
AS.Views.Stage = AS.Views.Panel.extend ({delegate, include, def, defs}) ->
def canvas_class: AS.Views.Canvas
def initialize: (config) ->
super
@_super.apply(this, arguments)
@canvas ?= AS.Views.Canvas.new()
@el.append @canvas.el
7 changes: 7 additions & 0 deletions lib/alpha_simprini/core/model/share.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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()) ->
model = AS.All.byId[id] or @new(id:id)
AS.openSharedObject id, (share) ->
Expand Down Expand Up @@ -78,6 +79,12 @@ AS.Model.Share = AS.Module.extend ({delegate, include, def, defs}) ->
def index: (name) ->
@share.at("index:#{name}")

def indexer: (name) ->
return (model) =>
@index(name).at(model.id).set model.constructor.path(), (error) ->
# AS.warn "FIXME: handle error in Model#indexer"
model.didIndex()

def loadIndeces: ->
indeces = @indeces()
loadedIndex = _.after indeces.length, _.bind(@indecesDidLoad, this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ AS.Models.MultipleSelectionModel = AS.Model.extend ({def}) ->

def initialize: ->
@_super()
@items = @selected()

@items.bind "add", (item) => @trigger("add", item)
@items.bind "remove", (item) => @trigger("remove", item)
Expand Down
2 changes: 1 addition & 1 deletion test/client/binding.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ exports.Binding =

# Collection:
# "field_value is the model": (test) ->
# [mocks, binding] = mock_binding(AS.Binding.Collection, model: new AS.Collection)
# [mocks, binding] = mock_binding(AS.Binding.Many, model: new AS.Collection)
# test.equal binding.pathValue(), binding.model
# test.done()

Expand Down
2 changes: 1 addition & 1 deletion test/client/view_events.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ exports.ViewEvents =

# def initialize: ->
# @_super()
# @default_state("left")
# @defaultState("left")

# view = StatelyView.new()
# view.trigger 'crank'
Expand Down
150 changes: 1 addition & 149 deletions test/core/model/share.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ exports["Model.Share"] =
"remoteop",
@model.share.at("index:docs", other.id).set(SimpleShare.path())
)

"loads models in indexes when opened": (test) ->
indexed = SimpleShare.new()
index = {}
Expand Down Expand Up @@ -131,68 +132,6 @@ exports["Model.Share"] =
test.equal undefined, @model.owner.get()
test.done()


# exports["Model.Share"] =
# setUp: (callback) ->
# @real_open = AS.openSharedObject

# AS.openSharedObject = (id, didOpen) ->
# didOpen makeDoc(id)

# @remote = (operation, model = @model) ->
# if model.share.emit
# model.share.emit "remoteop", operation
# else
# model.share.doc.emit "remoteop", operation

# @model_bindings = (model, test) ->
# model.field.set("value")
# test.equal model.share.at("field").get(), "value", "field model->share"

# added_relation = SimpleShare.shared()
# model.relations.add added_relation
# expected_has_many_value = {id: added_relation.id, _type: added_relation.constructor._type}
# test.deepEqual model.share.at("relations", 0).get(), expected_has_many_value, "has_many model->share"

# # model.embeds().add added_embed = SimpleShare.new()
# # test.deepEqual model.share.at("embeds", 0).get(), added_embed.attributesForSharing(), "embeds_many model->share"

# # model.embeds().remove added_embed
# # test.deepEqual model.share.at("embeds").get(), [], "embeds_many remove->share"

# # model.embedded set_embedded = SimpleShare.new()
# # test.deepEqual model.share.at("embedded").get(), set_embedded.attributesForSharing(), "embeds_one model->share"

# # model.owner set_owner = SimpleShare.shared()
# # test.deepEqual model.share.at("owner").get(), set_owner.id, "belongsTo model->share"

# # share = model.share

# # @remote share.at("field").insert(0, "!"), model
# # test.equal model.field(), "!value", "field share->model"

# # @remote share.at("field").insert(0, "OBOY "), model
# # test.equal model.field(), "OBOY !value", "field share->model; insert"

# # remote_relation = SimpleShare.shared()
# # @remote share.at("relations", model.relations().length).set(remote_relation.attributesForSharing()), model
# # test.deepEqual model.relations().last().value().attributesForSharing(), remote_relation.attributesForSharing(), "has_many share->model"

# # remote_embed = SimpleShare.shared()
# # @remote share.at("embeds", model.relations().length).set(remote_embed.attributesForSharing()), model
# # test.deepEqual model.embeds().last().value().attributesForSharing(), remote_embed.attributesForSharing(), "embeds_many share->model"

# # remote_embedded = SimpleShare.shared()
# # @remote share.at("embedded").set(remote_embedded.attributesForSharing()), model
# # test.deepEqual model.embedded().attributesForSharing(), remote_embedded.attributesForSharing(), "embeds_one share->model"

# # remote_owner = SimpleShare.shared()
# # @remote share.at("owner").set(remote_owner.id), model
# # test.equal model.owner().id, remote_owner.id, "belongsTo share->model"


# (@model = Shared.shared()).whenIndexed callback

"is new if share is undefined": (test) ->
delete @model.share
test.ok @model.new()
Expand Down Expand Up @@ -223,90 +162,3 @@ exports["Model.Share"] =
test.equal model.defaulted.get(), "REMOTE VALUE"

test.done()

# "sets initial attributes when opening an object": (test) ->
# test.deepEqual @model.share.get(), @model.attributesForSharing()
# test.done()

# "updates shared object when model attributes change": (test) ->
# @model.field.set("VALUE")
# test.equal @model.share.at("field").get(), "VALUE"

# test.done()

# "adds/removes items to relations in share": (test) ->
# @model_bindings(@model, test)
# test.done()

# "adds items to shared collection at specified index": (test) ->
# @model.relations().add SimpleShare.shared()
# @model.embeds().add SimpleShare.shared()

# @model.relations().add first_relation = SimpleShare.shared(), at: 0
# @model.embeds().add first_embed = SimpleShare.shared(), at: 0

# relation_attrs =
# id: first_relation.id
# _type: first_relation.constructor._type

# test.deepEqual relation_attrs, @model.share.at("relations", 0).get()
# test.deepEqual first_embed.attributesForSharing(), @model.share.at("embeds", 0).get()

# test.done()

# "updates fields in embeds_one models when change occurs on share": (test) ->
# test.expect 5

# @model.embedded first = SimpleShare.shared()
# @model.embedded().bind "change:field", -> test.ok true
# @remote @model.share.at("embedded", "field").set("value")
# test.equal first.field(), "value"

# # make sure when we swap out embeds the only the newer one is changed
# @model.embedded second = SimpleShare.shared()
# @model.embedded().bind "change:field", -> test.ok true
# @remote @model.share.at("embedded", "field").set("value2")
# test.notEqual first.field(), "value2"
# test.equal second.field(), "value2"

# test.done()

# "updates fields on embedded models created in this client": (test)->
# model = Shared.shared()
# attrs = SimpleShare.shared().attributesForSharing()
# attrs.id = "embeddedsharedid"
# @remote model.share.at("embeds").insert(0, attrs), model

# test.equal model.embeds().first().value().id, attrs.id

# embed = model.embeds().first().value()
# embed.field("!")
# test.equal embed.share.at("field").get(), "!"

# @remote embed.share.at("field").insert(0, "BOO"), embed

# test.equal embed.share.at("field").get(), "BOO!"

# test.equal embed.field(), "BOO!"

# test.done()

# "updates fields on models that have been received over the wire": (test) ->

# attrs = SimpleShare.shared().attributesForSharing()
# attrs.id = "someid"

# @remote @model.share.at("embeds", 0).set attrs
# @model_bindings @model.embeds.first().value.get(), test

# test.done()

# "updates belongsTo in has_many models when change occurs on share": (test) ->
# test.expect 2
# owner = SimpleShare.shared()
# @model.bind "change:owner", -> test.ok true
# @remote @model.share.at("owner").set(owner.id)
# test.equal @model.owner.get(), owner

# test.done()

0 comments on commit 4e17d2d

Please sign in to comment.