So guys, I'm in a bit little nightmare here. Starting using makoJs and Marko-widgets loving so far. But...
This is the thing I follow the organization of some samples and integrate with the lassoJS. So in the lasso way of doing things I do not get to implement the define component methods.
So what I need to accomplish:
module.exports = require('marko-widgets').defineComponent({
template: require('./template.marko'),
getInitialState: function(input) {
return {
name: input.name,
selected: input.selected || false;
}
},
getTemplateData: function(state, input) {
var style = ;
return {
name: state.name,
color: state.selected ? 'yellow' : 'transparent'
};
},
handleClick: function() {
this.setState('selected', true);
},
isSelected: function() {
return this.state.selected;
}
});
My Marko file is being writing as this:
import './style.css'
static function getClassNameForValue(value) {
if (value < 0) {
return 'negative';
} else if (value > 0) {
return 'positive';
}
}
class {
onInput(input) {
var value = input.value || 0;
this.state = {
value: value
};
}
handleIncrementClick(delta) {
this.state.value += delta;
var value = this.state.value;
var send = {
value:value
}
console.log(value);
$.post( "/tryPost", send,function( data ) {
console.log(data);
});
}
handleInputKeyUp(event, el) {
var newValue = el.value;
if (/^-?[0-9]+$/.test(newValue)) {
this.state.value = parseInt(newValue, 10);
}
}
}
$ var value=state.value;
<div class=['number-spinner', getClassNameForValue(value)]>
<button type="button" onClick("handleIncrementClick", -1)>
-
</button>
<input type="text" value=state.value size="4"
onKeyUp("handleInputKeyUp")>
<button type="button" onClick("handleIncrementClick", 1)>
+
</button>
</div>
Edit: So I was thinking, know what version of those modules I'm using could help.
"lasso": "^2.11.3",
"lasso-less": "^2.4.3",
"lasso-marko": "^2.2.2",
"lodash": "^4.17.4",
"markdown-js": "0.0.3",
"marked": "^0.3.6",
"marko": "^4.0.0-rc.18",
"marko-widgets": "^6.6.0"
So how, to implement the listener for events of the lifecycle?
I'm not quite sure what the question is, but with marko
v4, marko-widgets
should no longer be installed (only marko
should be installed). You'll want to do the following:
npm uninstall marko-widgets --save
We are still in the process of finalizing the v4 documentation, but maybe the following v4 docs on component lifecycle methods would help: https://github.com/marko-js/marko/blob/9b6a288d83fef926590f24368a40476c5ff0e240/docs/06-components.md#lifecycle
If things are still unclear, please join in the Gitter chat room: https://gitter.im/marko-js/marko