Skip to content

Instantly share code, notes, and snippets.

@magnusleo
Created August 3, 2016 09:50
Show Gist options
  • Save magnusleo/ac28737dd659db6465d9db47ab54495b to your computer and use it in GitHub Desktop.
Save magnusleo/ac28737dd659db6465d9db47ab54495b to your computer and use it in GitHub Desktop.
Mithril undefined vnode.state in node
"use strict";
var m = require('mithril');
var items = ['foo', 'bar', 'baz'];
module.exports = {
clickCurry: function(index) {
return function() {
console.log(index);
}
},
view: function(vnode) {
return m('ul', items.map(function(item, i) {
return m('li', {onclick: vnode.state.clickCurry(i)}, item); // Fails in node
// return m('li', {onclick: vnode.tag.clickCurry(i)}, item); // Works in both browser and node
})
);
},
};
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Test</title>
</head>
<body>
<div id="mount-point"></div>
<script src="demo.bundle.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>
"use strict";
var m = require('mithril');
var component = require('./component');
m.mount(document.getElementById('mount-point'), component);
{
"dependencies": {
"mithril": "github:lhorie/mithril.js#rewrite",
"webpack": "^1.12.14"
},
"devDependencies": {
"mithril-query": "github:stephanhoyer/mithril-query#rewrite",
"tape": "^4.5.1"
},
"scripts": {
"test": "tape test.js",
"build": "webpack --colors",
"watch": "webpack --watch --colors"
}
}
"use strict";
global.window = require('mithril/test-utils/domMock.js')()
global.window = Object.assign(global.window, require('mithril/test-utils/pushStateMock')())
var test = require('tape');
var mq = require('mithril-query');
var m = require('mithril');
var component = require('./component.js');
test('component', function(t) {
t.test('view', function(t) {
var $output = mq(m(component));
$output.should.have('ul');
t.end();
});
});
"use strict";
var path = require('path');
module.exports = {
context: path.join(__dirname, 'build'),
entry: {demo: __dirname + '/index.js'},
output: {
filename: '[name].bundle.js',
chunkFilename: '[id].bundle.js',
path: __dirname
},
module: {
loaders: []
},
resolve: {
extensions: ['', '.js']
},
plugins: [
],
devServer: {
contentBase: 'build/',
hot: true,
inline: true
},
debug: true,
devtool: '#inline-source-map'
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment