-
-
Save magnusleo/ac28737dd659db6465d9db47ab54495b to your computer and use it in GitHub Desktop.
Mithril undefined vnode.state in node
This file contains 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
"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 | |
}) | |
); | |
}, | |
}; |
This file contains 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
<!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> |
This file contains 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
"use strict"; | |
var m = require('mithril'); | |
var component = require('./component'); | |
m.mount(document.getElementById('mount-point'), component); |
This file contains 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
{ | |
"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" | |
} | |
} |
This file contains 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
"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(); | |
}); | |
}); |
This file contains 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
"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