Comparing version 3.0.0-1 to 3.0.0-2
@@ -38,8 +38,3 @@ 'use strict'; | ||
var v = children[i]; | ||
var w = v; | ||
if (isProperty(v)) { | ||
w = valueOf(v); | ||
} else if (I.isArray(v)) { | ||
w = renderChildren(v); | ||
} | ||
var w = isProperty(v) ? valueOf(v) : I.isArray(v) ? renderChildren(v) : v; | ||
if (v !== w) { | ||
@@ -96,6 +91,6 @@ if (newChildren === children) newChildren = children.slice(0); | ||
function forEachInChildren(children, extra, fn) { | ||
for (var i = 0, n = children.length; i < n; ++i) { | ||
function forEachInChildren(i, children, extra, fn) { | ||
for (var n = children.length; i < n; ++i) { | ||
var c = children[i]; | ||
if (isProperty(c)) fn(extra, c);else if (I.isArray(c)) forEachInChildren(c, extra, fn); | ||
if (isProperty(c)) fn(extra, c);else if (I.isArray(c)) forEachInChildren(0, c, extra, fn); | ||
} | ||
@@ -110,3 +105,3 @@ } | ||
} else if (CHILDREN === i) { | ||
if (I.isArray(v)) forEachInChildren(v, extra, fn); | ||
if (I.isArray(v)) forEachInChildren(0, v, extra, fn); | ||
} else if (STYLE === i || DANGEROUSLY === i) { | ||
@@ -145,5 +140,6 @@ for (var j in v) { | ||
if (handler) { | ||
var props = this.props.props; | ||
var args = this.props.args; | ||
forEachInProps(props, handler, offAny); | ||
forEachInChildren(2, args, handler, offAny); | ||
forEachInProps(args[1], handler, offAny); | ||
} | ||
@@ -154,16 +150,24 @@ }, | ||
var props = _ref.props; | ||
var args = _ref.args; | ||
forEachInProps(props, this.handler = function (e) { | ||
var handler = this.handler = function (e) { | ||
var type = e.type; | ||
if (type === VALUE) _this.forceUpdate();else if (type === ERROR) throw e.value;else _this.handler = null; | ||
}, onAny); | ||
}; | ||
forEachInProps(args[1], handler, onAny); | ||
forEachInChildren(2, args, handler, onAny); | ||
}, | ||
render: function render() { | ||
var _props = this.props, | ||
type = _props.type, | ||
props = _props.props; | ||
var args = this.props.args; | ||
return React.createElement(type, renderProps(props)); | ||
var n = args.length; | ||
var newArgs = Array(n); | ||
newArgs[0] = args[0]; | ||
newArgs[1] = renderProps(args[1]); | ||
for (var i = 2; i < n; ++i) { | ||
var v = args[i]; | ||
newArgs[i] = isProperty(v) ? valueOf(v) : I.isArray(v) ? renderChildren(v) : v; | ||
} | ||
return React.createElement.apply(null, newArgs); | ||
} | ||
@@ -174,6 +178,6 @@ }); | ||
function hasPropertiesInChildren(children) { | ||
for (var i = 0, n = children.length; i < n; ++i) { | ||
function hasPropertiesInChildren(i, children) { | ||
for (var n = children.length; i < n; ++i) { | ||
var c = children[i]; | ||
if (isProperty(c) || I.isArray(c) && hasPropertiesInChildren(c)) return true; | ||
if (isProperty(c) || I.isArray(c) && hasPropertiesInChildren(0, c)) return true; | ||
} | ||
@@ -189,3 +193,3 @@ return false; | ||
} else if (CHILDREN === i) { | ||
if (I.isArray(v) && hasPropertiesInChildren(v)) return true; | ||
if (I.isArray(v) && hasPropertiesInChildren(0, v)) return true; | ||
} else if (STYLE === i || DANGEROUSLY === i) { | ||
@@ -202,5 +206,6 @@ for (var j in v) { | ||
function considerLifting(type, props) { | ||
if (hasPropertiesInProps(props)) { | ||
var fromClassProps = { type: type, props: props }; | ||
function considerLifting(args) { | ||
var props = args[1]; | ||
if (hasPropertiesInProps(props) || hasPropertiesInChildren(2, args)) { | ||
var fromClassProps = { args: args }; | ||
if (props) { | ||
@@ -212,21 +217,18 @@ var key = props.key; | ||
} else { | ||
return React.createElement(type, props); | ||
return React.createElement.apply(null, args); | ||
} | ||
} | ||
function createElement(type, props, child) { | ||
var n = arguments.length; | ||
if (n > 2) { | ||
var children = n === 3 ? child : [child]; | ||
for (var i = 3; i < n; ++i) { | ||
children.push(arguments[i]); | ||
}props = I.assocPartialU('children', children, props); | ||
} | ||
if (props && props[LIFT]) { | ||
props = I.dissocPartialU(LIFT, props); | ||
return considerLifting(type, props); | ||
} else if (I.isString(type) || React.Fragment === type) { | ||
return considerLifting(type, props); | ||
function createElement(type, props, _child) { | ||
var lift = props && props[LIFT]; | ||
if (lift || I.isString(type) || React.Fragment === type) { | ||
var n = arguments.length; | ||
var args = Array(n); | ||
args[0] = type; | ||
args[1] = lift ? I.dissocPartialU(LIFT, props) : props; | ||
for (var i = 2; i < n; ++i) { | ||
args[i] = arguments[i]; | ||
}return considerLifting(args); | ||
} else { | ||
return React.createElement(type, props); | ||
return React.createElement.apply(null, arguments); | ||
} | ||
@@ -239,3 +241,3 @@ } | ||
return React.forwardRef(function (props, ref) { | ||
return considerLifting(type, undefined === ref ? props : I.assocPartialU('ref', ref, props)); | ||
return considerLifting([type, undefined === ref ? props : I.assocPartialU('ref', ref, props)]); | ||
}); | ||
@@ -242,0 +244,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
import { isArray, inherit, assocPartialU, dissocPartialU, isString } from 'infestines'; | ||
import { isArray, inherit, isString, dissocPartialU, assocPartialU } from 'infestines'; | ||
import { Component, createElement, Fragment, forwardRef } from 'react'; | ||
@@ -35,8 +35,3 @@ export { Fragment } from 'react'; | ||
var v = children[i]; | ||
var w = v; | ||
if (isProperty(v)) { | ||
w = valueOf(v); | ||
} else if (isArray(v)) { | ||
w = renderChildren(v); | ||
} | ||
var w = isProperty(v) ? valueOf(v) : isArray(v) ? renderChildren(v) : v; | ||
if (v !== w) { | ||
@@ -93,6 +88,6 @@ if (newChildren === children) newChildren = children.slice(0); | ||
function forEachInChildren(children, extra, fn) { | ||
for (var i = 0, n = children.length; i < n; ++i) { | ||
function forEachInChildren(i, children, extra, fn) { | ||
for (var n = children.length; i < n; ++i) { | ||
var c = children[i]; | ||
if (isProperty(c)) fn(extra, c);else if (isArray(c)) forEachInChildren(c, extra, fn); | ||
if (isProperty(c)) fn(extra, c);else if (isArray(c)) forEachInChildren(0, c, extra, fn); | ||
} | ||
@@ -107,3 +102,3 @@ } | ||
} else if (CHILDREN === i) { | ||
if (isArray(v)) forEachInChildren(v, extra, fn); | ||
if (isArray(v)) forEachInChildren(0, v, extra, fn); | ||
} else if (STYLE === i || DANGEROUSLY === i) { | ||
@@ -142,5 +137,6 @@ for (var j in v) { | ||
if (handler) { | ||
var props = this.props.props; | ||
var args = this.props.args; | ||
forEachInProps(props, handler, offAny); | ||
forEachInChildren(2, args, handler, offAny); | ||
forEachInProps(args[1], handler, offAny); | ||
} | ||
@@ -151,16 +147,24 @@ }, | ||
var props = _ref.props; | ||
var args = _ref.args; | ||
forEachInProps(props, this.handler = function (e) { | ||
var handler = this.handler = function (e) { | ||
var type = e.type; | ||
if (type === VALUE) _this.forceUpdate();else if (type === ERROR) throw e.value;else _this.handler = null; | ||
}, onAny); | ||
}; | ||
forEachInProps(args[1], handler, onAny); | ||
forEachInChildren(2, args, handler, onAny); | ||
}, | ||
render: function render() { | ||
var _props = this.props, | ||
type = _props.type, | ||
props = _props.props; | ||
var args = this.props.args; | ||
return createElement(type, renderProps(props)); | ||
var n = args.length; | ||
var newArgs = Array(n); | ||
newArgs[0] = args[0]; | ||
newArgs[1] = renderProps(args[1]); | ||
for (var i = 2; i < n; ++i) { | ||
var v = args[i]; | ||
newArgs[i] = isProperty(v) ? valueOf(v) : isArray(v) ? renderChildren(v) : v; | ||
} | ||
return createElement.apply(null, newArgs); | ||
} | ||
@@ -171,6 +175,6 @@ }); | ||
function hasPropertiesInChildren(children) { | ||
for (var i = 0, n = children.length; i < n; ++i) { | ||
function hasPropertiesInChildren(i, children) { | ||
for (var n = children.length; i < n; ++i) { | ||
var c = children[i]; | ||
if (isProperty(c) || isArray(c) && hasPropertiesInChildren(c)) return true; | ||
if (isProperty(c) || isArray(c) && hasPropertiesInChildren(0, c)) return true; | ||
} | ||
@@ -186,3 +190,3 @@ return false; | ||
} else if (CHILDREN === i) { | ||
if (isArray(v) && hasPropertiesInChildren(v)) return true; | ||
if (isArray(v) && hasPropertiesInChildren(0, v)) return true; | ||
} else if (STYLE === i || DANGEROUSLY === i) { | ||
@@ -199,5 +203,6 @@ for (var j in v) { | ||
function considerLifting(type, props) { | ||
if (hasPropertiesInProps(props)) { | ||
var fromClassProps = { type: type, props: props }; | ||
function considerLifting(args) { | ||
var props = args[1]; | ||
if (hasPropertiesInProps(props) || hasPropertiesInChildren(2, args)) { | ||
var fromClassProps = { args: args }; | ||
if (props) { | ||
@@ -209,21 +214,18 @@ var key = props.key; | ||
} else { | ||
return createElement(type, props); | ||
return createElement.apply(null, args); | ||
} | ||
} | ||
function createElement$1(type, props, child) { | ||
var n = arguments.length; | ||
if (n > 2) { | ||
var children = n === 3 ? child : [child]; | ||
for (var i = 3; i < n; ++i) { | ||
children.push(arguments[i]); | ||
}props = assocPartialU('children', children, props); | ||
} | ||
if (props && props[LIFT]) { | ||
props = dissocPartialU(LIFT, props); | ||
return considerLifting(type, props); | ||
} else if (isString(type) || Fragment === type) { | ||
return considerLifting(type, props); | ||
function createElement$1(type, props, _child) { | ||
var lift = props && props[LIFT]; | ||
if (lift || isString(type) || Fragment === type) { | ||
var n = arguments.length; | ||
var args = Array(n); | ||
args[0] = type; | ||
args[1] = lift ? dissocPartialU(LIFT, props) : props; | ||
for (var i = 2; i < n; ++i) { | ||
args[i] = arguments[i]; | ||
}return considerLifting(args); | ||
} else { | ||
return createElement(type, props); | ||
return createElement.apply(null, arguments); | ||
} | ||
@@ -236,3 +238,3 @@ } | ||
return forwardRef(function (props, ref) { | ||
return considerLifting(type, undefined === ref ? props : assocPartialU('ref', ref, props)); | ||
return considerLifting([type, undefined === ref ? props : assocPartialU('ref', ref, props)]); | ||
}); | ||
@@ -239,0 +241,0 @@ }; |
@@ -36,8 +36,3 @@ (function (global, factory) { | ||
var v = children[i]; | ||
var w = v; | ||
if (isProperty(v)) { | ||
w = valueOf(v); | ||
} else if (I.isArray(v)) { | ||
w = renderChildren(v); | ||
} | ||
var w = isProperty(v) ? valueOf(v) : I.isArray(v) ? renderChildren(v) : v; | ||
if (v !== w) { | ||
@@ -94,6 +89,6 @@ if (newChildren === children) newChildren = children.slice(0); | ||
function forEachInChildren(children, extra, fn) { | ||
for (var i = 0, n = children.length; i < n; ++i) { | ||
function forEachInChildren(i, children, extra, fn) { | ||
for (var n = children.length; i < n; ++i) { | ||
var c = children[i]; | ||
if (isProperty(c)) fn(extra, c);else if (I.isArray(c)) forEachInChildren(c, extra, fn); | ||
if (isProperty(c)) fn(extra, c);else if (I.isArray(c)) forEachInChildren(0, c, extra, fn); | ||
} | ||
@@ -108,3 +103,3 @@ } | ||
} else if (CHILDREN === i) { | ||
if (I.isArray(v)) forEachInChildren(v, extra, fn); | ||
if (I.isArray(v)) forEachInChildren(0, v, extra, fn); | ||
} else if (STYLE === i || DANGEROUSLY === i) { | ||
@@ -143,5 +138,6 @@ for (var j in v) { | ||
if (handler) { | ||
var props = this.props.props; | ||
var args = this.props.args; | ||
forEachInProps(props, handler, offAny); | ||
forEachInChildren(2, args, handler, offAny); | ||
forEachInProps(args[1], handler, offAny); | ||
} | ||
@@ -152,16 +148,24 @@ }, | ||
var props = _ref.props; | ||
var args = _ref.args; | ||
forEachInProps(props, this.handler = function (e) { | ||
var handler = this.handler = function (e) { | ||
var type = e.type; | ||
if (type === VALUE) _this.forceUpdate();else if (type === ERROR) throw e.value;else _this.handler = null; | ||
}, onAny); | ||
}; | ||
forEachInProps(args[1], handler, onAny); | ||
forEachInChildren(2, args, handler, onAny); | ||
}, | ||
render: function render() { | ||
var _props = this.props, | ||
type = _props.type, | ||
props = _props.props; | ||
var args = this.props.args; | ||
return React.createElement(type, renderProps(props)); | ||
var n = args.length; | ||
var newArgs = Array(n); | ||
newArgs[0] = args[0]; | ||
newArgs[1] = renderProps(args[1]); | ||
for (var i = 2; i < n; ++i) { | ||
var v = args[i]; | ||
newArgs[i] = isProperty(v) ? valueOf(v) : I.isArray(v) ? renderChildren(v) : v; | ||
} | ||
return React.createElement.apply(null, newArgs); | ||
} | ||
@@ -172,6 +176,6 @@ }); | ||
function hasPropertiesInChildren(children) { | ||
for (var i = 0, n = children.length; i < n; ++i) { | ||
function hasPropertiesInChildren(i, children) { | ||
for (var n = children.length; i < n; ++i) { | ||
var c = children[i]; | ||
if (isProperty(c) || I.isArray(c) && hasPropertiesInChildren(c)) return true; | ||
if (isProperty(c) || I.isArray(c) && hasPropertiesInChildren(0, c)) return true; | ||
} | ||
@@ -187,3 +191,3 @@ return false; | ||
} else if (CHILDREN === i) { | ||
if (I.isArray(v) && hasPropertiesInChildren(v)) return true; | ||
if (I.isArray(v) && hasPropertiesInChildren(0, v)) return true; | ||
} else if (STYLE === i || DANGEROUSLY === i) { | ||
@@ -200,5 +204,6 @@ for (var j in v) { | ||
function considerLifting(type, props) { | ||
if (hasPropertiesInProps(props)) { | ||
var fromClassProps = { type: type, props: props }; | ||
function considerLifting(args) { | ||
var props = args[1]; | ||
if (hasPropertiesInProps(props) || hasPropertiesInChildren(2, args)) { | ||
var fromClassProps = { args: args }; | ||
if (props) { | ||
@@ -210,21 +215,18 @@ var key = props.key; | ||
} else { | ||
return React.createElement(type, props); | ||
return React.createElement.apply(null, args); | ||
} | ||
} | ||
function createElement(type, props, child) { | ||
var n = arguments.length; | ||
if (n > 2) { | ||
var children = n === 3 ? child : [child]; | ||
for (var i = 3; i < n; ++i) { | ||
children.push(arguments[i]); | ||
}props = I.assocPartialU('children', children, props); | ||
} | ||
if (props && props[LIFT]) { | ||
props = I.dissocPartialU(LIFT, props); | ||
return considerLifting(type, props); | ||
} else if (I.isString(type) || React.Fragment === type) { | ||
return considerLifting(type, props); | ||
function createElement(type, props, _child) { | ||
var lift = props && props[LIFT]; | ||
if (lift || I.isString(type) || React.Fragment === type) { | ||
var n = arguments.length; | ||
var args = Array(n); | ||
args[0] = type; | ||
args[1] = lift ? I.dissocPartialU(LIFT, props) : props; | ||
for (var i = 2; i < n; ++i) { | ||
args[i] = arguments[i]; | ||
}return considerLifting(args); | ||
} else { | ||
return React.createElement(type, props); | ||
return React.createElement.apply(null, arguments); | ||
} | ||
@@ -237,3 +239,3 @@ } | ||
return React.forwardRef(function (props, ref) { | ||
return considerLifting(type, undefined === ref ? props : I.assocPartialU('ref', ref, props)); | ||
return considerLifting([type, undefined === ref ? props : I.assocPartialU('ref', ref, props)]); | ||
}); | ||
@@ -240,0 +242,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("infestines"),require("react"),require("kefir")):"function"==typeof define&&define.amd?define(["exports","infestines","react","kefir"],e):e(r.karet={},r.I,r.React,r.Kefir)}(this,function(r,e,n,t){"use strict";function i(r){var e=r._currentEvent;if(e)return e.value}function o(r){for(var n=r,t=0,f=r.length;t<f;++t){var a=r[t],u=a;y(a)?u=i(a):e.isArray(a)&&(u=o(a)),a!==u&&(n===r&&(n=r.slice(0)),n[t]=u)}return n}function f(r){var e=null;for(var n in r){var t=r[n];if(y(t)){if(!e)for(var o in e={},r){if(o===n)break;e[o]=r[o]}e[n]=i(t)}else e&&(e[n]=t)}return e||r}function a(r,n,t){for(var i=0,o=r.length;i<o;++i){var f=r[i];y(f)?t(n,f):e.isArray(f)&&a(f,n,t)}}function u(r,n,t){for(var i in r){var o=r[i];if(y(o))t(n,o);else if(d===i)e.isArray(o)&&a(o,n,t);else if(p===i||h===i)for(var f in o){var u=o[f];y(u)&&t(n,u)}}}function s(r,e){e.offAny(r)}function l(r,e){e.onAny(r)}function c(r){for(var n=0,t=r.length;n<t;++n){var i=r[n];if(y(i)||e.isArray(i)&&c(i))return!0}return!1}function v(r,t){if(function(r){for(var n in r){var t=r[n];if(y(t))return!0;if(d===n){if(e.isArray(t)&&c(t))return!0}else if(p===n||h===n)for(var i in t)if(y(t[i]))return!0}return!1}(t)){var i={type:r,props:t};if(t){var o=t.key;null!=o&&(i.key=o)}return n.createElement(m,i)}return n.createElement(r,t)}var p="style",h="dangerouslySetInnerHTML",d="children",y=function(r){return r instanceof t.Property},m=e.inherit(function(r){n.Component.call(this,r),this.handler=null},n.Component,{componentWillMount:function(){this.doSubscribe(this.props)},componentWillReceiveProps:function(r){this.componentWillUnmount(),this.doSubscribe(r)},componentWillUnmount:function(){var r=this.handler;r&&u(this.props.props,r,s)},doSubscribe:function(r){var e=this;u(r.props,this.handler=function(r){var n=r.type;if("value"===n)e.forceUpdate();else{if("error"===n)throw r.value;e.handler=null}},l)},render:function(){var r=this.props;return n.createElement(r.type,function(r){var n=null;for(var t in r){var a=r[t],u=y(a)?i(a):d===t?e.isArray(a)?o(a):a:p===t||h===t?f(a):a;if(a!==u){if(!n)for(var s in n={},r){if(s===t)break;n[s]=r[s]}n[t]=u}else n&&(n[t]=u)}return n||r}(r.props))}});r.Fragment=n.Fragment,r.createElement=function(r,t,i){var o=arguments.length;if(o>2){for(var f=3===o?i:[i],a=3;a<o;++a)f.push(arguments[a]);t=e.assocPartialU("children",f,t)}return t&&t["karet-lift"]?v(r,t=e.dissocPartialU("karet-lift",t)):e.isString(r)||n.Fragment===r?v(r,t):n.createElement(r,t)},r.fromClass=function(r){return n.forwardRef(function(n,t){return v(r,void 0===t?n:e.assocPartialU("ref",t,n))})},Object.defineProperty(r,"__esModule",{value:!0})}); | ||
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("infestines"),require("react"),require("kefir")):"function"==typeof define&&define.amd?define(["exports","infestines","react","kefir"],e):e(r.karet={},r.I,r.React,r.Kefir)}(this,function(r,e,n,t){"use strict";function i(r){var e=r._currentEvent;if(e)return e.value}function a(r){for(var n=r,t=0,f=r.length;t<f;++t){var o=r[t],u=d(o)?i(o):e.isArray(o)?a(o):o;o!==u&&(n===r&&(n=r.slice(0)),n[t]=u)}return n}function f(r){var e=null;for(var n in r){var t=r[n];if(d(t)){if(!e)for(var a in e={},r){if(a===n)break;e[a]=r[a]}e[n]=i(t)}else e&&(e[n]=t)}return e||r}function o(r,n,t,i){for(var a=n.length;r<a;++r){var f=n[r];d(f)?i(t,f):e.isArray(f)&&o(0,f,t,i)}}function u(r,n,t){for(var i in r){var a=r[i];if(d(a))t(n,a);else if(y===i)e.isArray(a)&&o(0,a,n,t);else if(p===i||h===i)for(var f in a){var u=a[f];d(u)&&t(n,u)}}}function l(r,e){e.offAny(r)}function s(r,e){e.onAny(r)}function c(r,n){for(var t=n.length;r<t;++r){var i=n[r];if(d(i)||e.isArray(i)&&c(0,i))return!0}return!1}function v(r){var t=r[1];if(function(r){for(var n in r){var t=r[n];if(d(t))return!0;if(y===n){if(e.isArray(t)&&c(0,t))return!0}else if(p===n||h===n)for(var i in t)if(d(t[i]))return!0}return!1}(t)||c(2,r)){var i={args:r};if(t){var a=t.key;null!=a&&(i.key=a)}return n.createElement(m,i)}return n.createElement.apply(null,r)}var p="style",h="dangerouslySetInnerHTML",y="children",d=function(r){return r instanceof t.Property},m=e.inherit(function(r){n.Component.call(this,r),this.handler=null},n.Component,{componentWillMount:function(){this.doSubscribe(this.props)},componentWillReceiveProps:function(r){this.componentWillUnmount(),this.doSubscribe(r)},componentWillUnmount:function(){var r=this.handler;if(r){var e=this.props.args;o(2,e,r,l),u(e[1],r,l)}},doSubscribe:function(r){var e=this,n=r.args,t=this.handler=function(r){var n=r.type;if("value"===n)e.forceUpdate();else{if("error"===n)throw r.value;e.handler=null}};u(n[1],t,s),o(2,n,t,s)},render:function(){var r=this.props.args,t=r.length,o=Array(t);o[0]=r[0],o[1]=function(r){var n=null;for(var t in r){var o=r[t],u=d(o)?i(o):y===t?e.isArray(o)?a(o):o:p===t||h===t?f(o):o;if(o!==u){if(!n)for(var l in n={},r){if(l===t)break;n[l]=r[l]}n[t]=u}else n&&(n[t]=u)}return n||r}(r[1]);for(var u=2;u<t;++u){var l=r[u];o[u]=d(l)?i(l):e.isArray(l)?a(l):l}return n.createElement.apply(null,o)}});r.Fragment=n.Fragment,r.createElement=function(r,t,i){var a=t&&t["karet-lift"];if(a||e.isString(r)||n.Fragment===r){var f=arguments.length,o=Array(f);o[0]=r,o[1]=a?e.dissocPartialU("karet-lift",t):t;for(var u=2;u<f;++u)o[u]=arguments[u];return v(o)}return n.createElement.apply(null,arguments)},r.fromClass=function(r){return n.forwardRef(function(n,t){return v([r,void 0===t?n:e.assocPartialU("ref",t,n)])})},Object.defineProperty(r,"__esModule",{value:!0})}); |
{ | ||
"name": "karet", | ||
"version": "3.0.0-1", | ||
"version": "3.0.0-2", | ||
"description": "Karet is a library that allows you to embed Kefir properties into React VDOM", | ||
@@ -5,0 +5,0 @@ "module": "dist/karet.es.js", |
@@ -32,8 +32,3 @@ import * as I from 'infestines' | ||
const v = children[i] | ||
let w = v | ||
if (isProperty(v)) { | ||
w = valueOf(v) | ||
} else if (I.isArray(v)) { | ||
w = renderChildren(v) | ||
} | ||
const w = isProperty(v) ? valueOf(v) : I.isArray(v) ? renderChildren(v) : v | ||
if (v !== w) { | ||
@@ -94,7 +89,7 @@ if (newChildren === children) newChildren = children.slice(0) | ||
function forEachInChildren(children, extra, fn) { | ||
for (let i = 0, n = children.length; i < n; ++i) { | ||
function forEachInChildren(i, children, extra, fn) { | ||
for (let n = children.length; i < n; ++i) { | ||
const c = children[i] | ||
if (isProperty(c)) fn(extra, c) | ||
else if (I.isArray(c)) forEachInChildren(c, extra, fn) | ||
else if (I.isArray(c)) forEachInChildren(0, c, extra, fn) | ||
} | ||
@@ -109,3 +104,3 @@ } | ||
} else if (CHILDREN === i) { | ||
if (I.isArray(v)) forEachInChildren(v, extra, fn) | ||
if (I.isArray(v)) forEachInChildren(0, v, extra, fn) | ||
} else if (STYLE === i || DANGEROUSLY === i) { | ||
@@ -147,21 +142,30 @@ for (const j in v) { | ||
if (handler) { | ||
const {props} = this.props | ||
forEachInProps(props, handler, offAny) | ||
const {args} = this.props | ||
forEachInChildren(2, args, handler, offAny) | ||
forEachInProps(args[1], handler, offAny) | ||
} | ||
}, | ||
doSubscribe({props}) { | ||
forEachInProps( | ||
props, | ||
(this.handler = e => { | ||
const {type} = e | ||
if (type === VALUE) this.forceUpdate() | ||
else if (type === ERROR) throw e.value | ||
else this.handler = null | ||
}), | ||
onAny | ||
) | ||
doSubscribe({args}) { | ||
const handler = (this.handler = e => { | ||
const {type} = e | ||
if (type === VALUE) this.forceUpdate() | ||
else if (type === ERROR) throw e.value | ||
else this.handler = null | ||
}) | ||
forEachInProps(args[1], handler, onAny) | ||
forEachInChildren(2, args, handler, onAny) | ||
}, | ||
render() { | ||
const {type, props} = this.props | ||
return React.createElement(type, renderProps(props)) | ||
const {args} = this.props | ||
const n = args.length | ||
const newArgs = Array(n) | ||
newArgs[0] = args[0] | ||
newArgs[1] = renderProps(args[1]) | ||
for (let i = 2; i < n; ++i) { | ||
const v = args[i] | ||
newArgs[i] = isProperty(v) | ||
? valueOf(v) | ||
: I.isArray(v) ? renderChildren(v) : v | ||
} | ||
return React.createElement.apply(null, newArgs) | ||
} | ||
@@ -173,6 +177,6 @@ } | ||
function hasPropertiesInChildren(children) { | ||
for (let i = 0, n = children.length; i < n; ++i) { | ||
function hasPropertiesInChildren(i, children) { | ||
for (let n = children.length; i < n; ++i) { | ||
const c = children[i] | ||
if (isProperty(c) || (I.isArray(c) && hasPropertiesInChildren(c))) | ||
if (isProperty(c) || (I.isArray(c) && hasPropertiesInChildren(0, c))) | ||
return true | ||
@@ -189,3 +193,3 @@ } | ||
} else if (CHILDREN === i) { | ||
if (I.isArray(v) && hasPropertiesInChildren(v)) return true | ||
if (I.isArray(v) && hasPropertiesInChildren(0, v)) return true | ||
} else if (STYLE === i || DANGEROUSLY === i) { | ||
@@ -200,5 +204,6 @@ for (const j in v) if (isProperty(v[j])) return true | ||
function considerLifting(type, props) { | ||
if (hasPropertiesInProps(props)) { | ||
const fromClassProps = {type, props} | ||
function considerLifting(args) { | ||
const props = args[1] | ||
if (hasPropertiesInProps(props) || hasPropertiesInChildren(2, args)) { | ||
const fromClassProps = {args} | ||
if (props) { | ||
@@ -210,20 +215,17 @@ const key = props.key | ||
} else { | ||
return React.createElement(type, props) | ||
return React.createElement.apply(null, args) | ||
} | ||
} | ||
export function createElement(type, props, child) { | ||
const n = arguments.length | ||
if (n > 2) { | ||
const children = n === 3 ? child : [child] | ||
for (let i = 3; i < n; ++i) children.push(arguments[i]) | ||
props = I.assocPartialU('children', children, props) | ||
} | ||
if (props && props[LIFT]) { | ||
props = I.dissocPartialU(LIFT, props) | ||
return considerLifting(type, props) | ||
} else if (I.isString(type) || React.Fragment === type) { | ||
return considerLifting(type, props) | ||
export function createElement(type, props, _child) { | ||
const lift = props && props[LIFT] | ||
if (lift || I.isString(type) || React.Fragment === type) { | ||
const n = arguments.length | ||
const args = Array(n) | ||
args[0] = type | ||
args[1] = lift ? I.dissocPartialU(LIFT, props) : props | ||
for (let i = 2; i < n; ++i) args[i] = arguments[i] | ||
return considerLifting(args) | ||
} else { | ||
return React.createElement(type, props) | ||
return React.createElement.apply(null, arguments) | ||
} | ||
@@ -236,6 +238,6 @@ } | ||
React.forwardRef((props, ref) => | ||
considerLifting( | ||
considerLifting([ | ||
type, | ||
undefined === ref ? props : I.assocPartialU('ref', ref, props) | ||
) | ||
]) | ||
) | ||
@@ -242,0 +244,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
101984
1361