Last active
August 29, 2015 14:02
-
-
Save Sequoia/c52ff4ba97cf64c1325f to your computer and use it in GitHub Desktop.
Why, when I use `m.module`, does it not automatically rerender the view?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////app.js | |
define([ 'mithril', 'propertyPane'], | |
function(m, propertyPane){ | |
//div#properties exists | |
m.module(document.getElementById('properties'),propertyPane); | |
}); | |
///////propertyPane.js | |
define([ 'mithril', 'emitter'], | |
function(m, emitter) { | |
//mithril "namespace" | |
var propertyPane = {}; | |
/////////////////////// | |
// Models // | |
/////////////////////// | |
propertyPane.PropertyList = Array; | |
propertyPane.Property = function(name, data) { | |
//the following reflects the format of the data obects as sent by the event emitter | |
this.name = m.prop(name); | |
this.value = m.prop(data.value); | |
this.type = m.prop(data.valueType); | |
this.visible = m.prop(data.userVisible); | |
this.editable = m.prop(data.userEditable); | |
}; | |
/////////////////////// | |
// Controller // | |
/////////////////////// | |
propertyPane.controller = function() { | |
this.properties = propertyPane.PropertyList(); | |
this.updatePropertyPane = function(sender) { | |
//destroy current list | |
this.properties.length = 0; | |
for( var key in sender.currentItem.tag){ | |
this.properties.push(new propertyPane.Property(key, sender.currentItem.tag[key])); | |
} | |
//>>>This is required to make the property pane to rerender:<<< | |
// m.redraw(); //why? | |
//why doesn't redraw happen automatically (because I'm using m.module)?? | |
}.bind(this); | |
//this reliably updates the the properties list | |
//but rerender does not happen | |
emitter.addCurrentItemChangedListener(this.updatePropertyPane); | |
}; | |
/////////////////////// | |
// View // | |
/////////////////////// | |
propertyPane.view = function(ctrl){ | |
return m('ul', | |
ctrl.properties.map(function(property){ | |
return m('li', property.name() + ' ' + property.value()); | |
}) | |
); | |
}; | |
return propertyPane; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment