mithril-node-render
Advanced tools
Comparing version 2.2.0 to 2.3.0
21
index.js
@@ -24,7 +24,4 @@ 'use strict' | ||
function isClass(thing) { | ||
return isFunction(thing) && ( | ||
/^\s*class\s/.test(thing.toString()) || // ES6 class | ||
/^\s*_classCallCheck\(/.test(thing.toString().replace(/^[^{]+{/, '')) // Babel class | ||
) | ||
function isClassComponent(thing) { | ||
return thing.prototype != null && typeof thing.prototype.view === "function" | ||
} | ||
@@ -43,8 +40,6 @@ | ||
keys = keys || [] | ||
var res = {} | ||
for (var k in source) { | ||
if (keys.indexOf(k) < 0) { | ||
res[k] = source[k] | ||
} | ||
} | ||
var res = Object.assign( Object.create( Object.getPrototypeOf(source)), source) | ||
keys.forEach(function(key) { | ||
if (key in res) { res[key] = null } | ||
}); | ||
return res | ||
@@ -128,3 +123,3 @@ } | ||
options = options || {} | ||
if (view.view || isClass(view)) { // root component | ||
if (view.view || isFunction(view)) { // root component | ||
view = m(view, attrs) | ||
@@ -186,3 +181,3 @@ } else { | ||
component = view.tag | ||
} else if (isClass(view.tag)) { | ||
} else if (isClassComponent(view.tag)) { | ||
component = new view.tag(vnode) | ||
@@ -189,0 +184,0 @@ } else if (isFunction(view.tag)) { |
{ | ||
"name": "mithril-node-render", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "Node rending of mithril views", | ||
@@ -26,5 +26,10 @@ "main": "index.js", | ||
"dependencies": { | ||
"co": "4.6.0", | ||
"mithril": "1.1.3" | ||
"co": "4.6.0" | ||
}, | ||
"peerDependencies": { | ||
"mithril": "^1.1.5" | ||
}, | ||
"devDependencies": { | ||
"mithril": "1.1.5" | ||
} | ||
} |
@@ -28,6 +28,6 @@ mithril-node-render | ||
// use a mock DOM so we can run mithril on the server | ||
require('mithril/test-utils/browserMock')(global); | ||
require('mithril/test-utils/browserMock')(global) | ||
var m = require('mithril'); | ||
var render = require('mithril-node-render'); | ||
var m = require('mithril') | ||
var render = require('mithril-node-render') | ||
@@ -46,18 +46,17 @@ render(m('span', 'huhu')).then(function (html) { | ||
```javascript | ||
myAsyncComponent = { | ||
oninit: function (node) { | ||
return new Promise(function (resolve) { | ||
node.state.foo = 'bar' | ||
resolve() | ||
}) | ||
}, | ||
view: function (node) { | ||
return m('div', node.state.foo) | ||
} | ||
var myAsyncComponent = { | ||
oninit: function (node) { | ||
return new Promise(function (resolve) { | ||
node.state.foo = 'bar' | ||
resolve() | ||
}) | ||
}, | ||
view: function (node) { | ||
return m('div', node.state.foo) | ||
} | ||
} | ||
// usage | ||
render(myAsyncComponent).then(function (html) { | ||
// html === '<div>bar</div>' | ||
} | ||
render(myAsyncComponent).then(function (html) { | ||
// html === '<div>bar</div>' | ||
}) | ||
``` | ||
@@ -64,0 +63,0 @@ |
@@ -11,2 +11,3 @@ 'use strict' | ||
var BabelClassComponent = require('./tests/fixtures/babel_class_component'); | ||
var FunctionClassComponent = require('./tests/fixtures/function_class_component'); | ||
@@ -136,3 +137,3 @@ o.async = function async (desc, genFn) { | ||
var classComponents = { es6: ES6ClassComponent, babel: BabelClassComponent } | ||
var classComponents = { es6: ES6ClassComponent, babel: BabelClassComponent, function: FunctionClassComponent } | ||
for (var type in classComponents) { | ||
@@ -139,0 +140,0 @@ o.spec('component of ' + type + ' class', function () { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26616
11
591
1
88
+ Addedmithril@1.1.7(transitive)
- Removedmithril@1.1.3
- Removedmithril@1.1.3(transitive)