Skip to content

Commit

Permalink
switching to pass in the model
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredly committed Apr 16, 2014
1 parent 4de868c commit 97f5ff3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 24 deletions.
7 changes: 3 additions & 4 deletions demo/workflowy/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@

function WFController(root, ids, options) {
function WFController(model, options) {
options = merge({
Model: WFModel,
viewOptions: {
ViewLayer: WFVL,
},
onBullet: function () {}
}, options)
Controller.call(this, root, ids, options)
this.o.onBullet(this.model.getLineage(root))
Controller.call(this, model, options)
this.o.onBullet(this.model.getLineage(model.root))
}

WFController.prototype = Object.create(Controller.prototype)
Expand Down
3 changes: 2 additions & 1 deletion demo/workflowy/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ var MainApp = React.createClass({

var Workflowy = React.createClass({
componentDidMount: function () {
this.wf = new WFController(this.props.id, this.props.tree, {onBullet: this.props.onBreadCrumb})
this.model = new WFModel(this.props.id, this.props.tree, null)
this.wf = new WFController(this.model, {onBullet: this.props.onBreadCrumb})
this.getDOMNode().appendChild(this.wf.node)
},
render: function () {
Expand Down
15 changes: 8 additions & 7 deletions lib/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ function makeCommand(type, args) {
return {type: type, data: data}
}

function Controller(root, ids, o) {
function Controller(model, o) {
o = o || {viewOptions: {}}
this.o = extend({
Model: Model,
View: View,
}, o)
this.o.viewOptions = extend({
node: DefaultNode
}, o.viewOptions)
this.model = new this.o.Model(root, ids, null)
this.view = new this.o.View(this.bindActions.bind(this),
this.model, this,
this.o.viewOptions)
this.node = this.view.initialize(root, ids)
this.model = model
this.view = new this.o.View(
this.bindActions.bind(this),
this.model, this,
this.o.viewOptions
)
this.node = this.view.initialize(model.root)
this.clipboard = null
this.commands = []
this.histpos = 0
Expand Down
12 changes: 0 additions & 12 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,6 @@ Model.prototype = {
}

return this.createNodes(pid, index, data)
/*
var before = false
if (index < parent.children.length - 1) {
before = parent.children[index + 1]
}
return {
node: node,
before: beforeId
}
*/
},

createNodes: function (pid, index, data) {
Expand Down Expand Up @@ -98,7 +87,6 @@ Model.prototype = {
if (index < this.ids[pid].children.length - 1) {
before = this.ids[pid].children[index + 1]
}
// this.dom.add(node, before, this.bounds(node.id))

return {
node: node,
Expand Down

0 comments on commit 97f5ff3

Please sign in to comment.