|
Line 0
a/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/inferno/dist/bundle.js_sec1
|
|
|
1 |
/******/ (function(modules) { // webpackBootstrap |
| 2 |
/******/ // The module cache |
| 3 |
/******/ var installedModules = {}; |
| 4 |
|
| 5 |
/******/ // The require function |
| 6 |
/******/ function __webpack_require__(moduleId) { |
| 7 |
|
| 8 |
/******/ // Check if module is in cache |
| 9 |
/******/ if(installedModules[moduleId]) |
| 10 |
/******/ return installedModules[moduleId].exports; |
| 11 |
|
| 12 |
/******/ // Create a new module (and put it into the cache) |
| 13 |
/******/ var module = installedModules[moduleId] = { |
| 14 |
/******/ exports: {}, |
| 15 |
/******/ id: moduleId, |
| 16 |
/******/ loaded: false |
| 17 |
/******/ }; |
| 18 |
|
| 19 |
/******/ // Execute the module function |
| 20 |
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); |
| 21 |
|
| 22 |
/******/ // Flag the module as loaded |
| 23 |
/******/ module.loaded = true; |
| 24 |
|
| 25 |
/******/ // Return the exports of the module |
| 26 |
/******/ return module.exports; |
| 27 |
/******/ } |
| 28 |
|
| 29 |
|
| 30 |
/******/ // expose the modules object (__webpack_modules__) |
| 31 |
/******/ __webpack_require__.m = modules; |
| 32 |
|
| 33 |
/******/ // expose the module cache |
| 34 |
/******/ __webpack_require__.c = installedModules; |
| 35 |
|
| 36 |
/******/ // __webpack_public_path__ |
| 37 |
/******/ __webpack_require__.p = "dist"; |
| 38 |
|
| 39 |
/******/ // Load entry module and return exports |
| 40 |
/******/ return __webpack_require__(0); |
| 41 |
/******/ }) |
| 42 |
/************************************************************************/ |
| 43 |
/******/ ([ |
| 44 |
/* 0 */ |
| 45 |
/***/ function(module, exports, __webpack_require__) { |
| 46 |
|
| 47 |
'use strict'; |
| 48 |
|
| 49 |
var _inferno = __webpack_require__(1); |
| 50 |
|
| 51 |
var _inferno2 = _interopRequireDefault(_inferno); |
| 52 |
|
| 53 |
var _infernoComponent = __webpack_require__(3); |
| 54 |
|
| 55 |
var _infernoComponent2 = _interopRequireDefault(_infernoComponent); |
| 56 |
|
| 57 |
var _share = __webpack_require__(5); |
| 58 |
|
| 59 |
var _base = __webpack_require__(6); |
| 60 |
|
| 61 |
var _model = __webpack_require__(7); |
| 62 |
|
| 63 |
var _model2 = _interopRequireDefault(_model); |
| 64 |
|
| 65 |
var _item = __webpack_require__(8); |
| 66 |
|
| 67 |
var _item2 = _interopRequireDefault(_item); |
| 68 |
|
| 69 |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
| 70 |
|
| 71 |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
| 72 |
|
| 73 |
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } |
| 74 |
|
| 75 |
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } |
| 76 |
|
| 77 |
var render = _inferno2.default.render; |
| 78 |
|
| 79 |
var model = new _model2.default(); |
| 80 |
|
| 81 |
var App = function (_Component) { |
| 82 |
_inherits(App, _Component); |
| 83 |
|
| 84 |
function App() { |
| 85 |
var _temp, _this, _ret; |
| 86 |
|
| 87 |
_classCallCheck(this, App); |
| 88 |
|
| 89 |
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { |
| 90 |
args[_key] = arguments[_key]; |
| 91 |
} |
| 92 |
|
| 93 |
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.state = { |
| 94 |
route: (0, _share.read)(), |
| 95 |
todos: model.get() |
| 96 |
}, _this.update = function (arr) { |
| 97 |
return _this.setState({ todos: arr }); |
| 98 |
}, _this.componentWillMount = function () { |
| 99 |
window.onhashchange = function () { |
| 100 |
return _this.setState({ route: (0, _share.read)() }); |
| 101 |
}; |
| 102 |
}, _this.add = function (e) { |
| 103 |
if (e.which !== _share.ENTER) return; |
| 104 |
|
| 105 |
var val = e.target.value.trim(); |
| 106 |
if (!val) return; |
| 107 |
|
| 108 |
e.target.value = ''; |
| 109 |
_this.update(model.add(val)); |
| 110 |
}, _this.edit = function (todo, val) { |
| 111 |
val = val.trim(); |
| 112 |
if (val.length) { |
| 113 |
_this.update(model.put(todo, { title: val, editing: 0 })); |
| 114 |
} else { |
| 115 |
_this.remove(todo); |
| 116 |
} |
| 117 |
}, _this.focus = function (todo) { |
| 118 |
return _this.update(model.put(todo, { editing: 1 })); |
| 119 |
}, _this.blur = function (todo) { |
| 120 |
return _this.update(model.put(todo, { editing: 0 })); |
| 121 |
}, _this.remove = function (todo) { |
| 122 |
return _this.update(model.del(todo)); |
| 123 |
}, _this.toggleOne = function (todo) { |
| 124 |
return _this.update(model.toggle(todo)); |
| 125 |
}, _this.toggleAll = function (ev) { |
| 126 |
return _this.update(model.toggleAll(ev.target.checked)); |
| 127 |
}, _this.clearCompleted = function () { |
| 128 |
return _this.update(model.clearCompleted()); |
| 129 |
}, _temp), _possibleConstructorReturn(_this, _ret); |
| 130 |
} |
| 131 |
|
| 132 |
App.prototype.render = function render(_, _ref) { |
| 133 |
var _this2 = this; |
| 134 |
|
| 135 |
var todos = _ref.todos, |
| 136 |
route = _ref.route; |
| 137 |
|
| 138 |
var num = todos.length; |
| 139 |
var shown = todos.filter(_share.filters[route]); |
| 140 |
var numDone = todos.filter(_share.filters.completed).length; |
| 141 |
var numAct = num - numDone; |
| 142 |
|
| 143 |
return _inferno2.default.createVNode(2, 'div', null, [_inferno2.default.createVNode(16, _base.Head, { |
| 144 |
'onEnter': this.add |
| 145 |
}), num ? _inferno2.default.createVNode(2, 'section', { |
| 146 |
'className': 'main' |
| 147 |
}, [_inferno2.default.createVNode(512, 'input', { |
| 148 |
'className': 'toggle-all', |
| 149 |
'type': 'checkbox', |
| 150 |
'checked': numAct === 0 |
| 151 |
}, null, { |
| 152 |
'onClick': this.toggleAll |
| 153 |
}), _inferno2.default.createVNode(2, 'ul', { |
| 154 |
'className': 'todo-list' |
| 155 |
}, shown.map(function (t) { |
| 156 |
return _inferno2.default.createVNode(16, _item2.default, { |
| 157 |
'data': t, |
| 158 |
'onBlur': function onBlur() { |
| 159 |
return _this2.blur(t); |
| 160 |
}, |
| 161 |
'onFocus': function onFocus() { |
| 162 |
return _this2.focus(t); |
| 163 |
}, |
| 164 |
'doDelete': function doDelete() { |
| 165 |
return _this2.remove(t); |
| 166 |
}, |
| 167 |
'doSave': function doSave(val) { |
| 168 |
return _this2.edit(t, val); |
| 169 |
}, |
| 170 |
'doToggle': function doToggle() { |
| 171 |
return _this2.toggleOne(t); |
| 172 |
} |
| 173 |
}); |
| 174 |
}))]) : null, numAct || numDone ? _inferno2.default.createVNode(16, _base.Foot, { |
| 175 |
'onClear': this.clearCompleted, |
| 176 |
'left': numAct, |
| 177 |
'done': numDone, |
| 178 |
'route': route |
| 179 |
}) : null]); |
| 180 |
}; |
| 181 |
|
| 182 |
return App; |
| 183 |
}(_infernoComponent2.default); |
| 184 |
|
| 185 |
render(_inferno2.default.createVNode(16, App), document.getElementById('app')); |
| 186 |
|
| 187 |
/***/ }, |
| 188 |
/* 1 */ |
| 189 |
/***/ function(module, exports, __webpack_require__) { |
| 190 |
|
| 191 |
module.exports = __webpack_require__(2); |
| 192 |
|
| 193 |
|
| 194 |
/***/ }, |
| 195 |
/* 2 */ |
| 196 |
/***/ function(module, exports, __webpack_require__) { |
| 197 |
|
| 198 |
/*! |
| 199 |
* inferno v1.0.0-beta32 |
| 200 |
* (c) 2016 Dominic Gannaway |
| 201 |
* Released under the MIT License. |
| 202 |
*/ |
| 203 |
(function (global, factory) { |
| 204 |
true ? factory(exports) : |
| 205 |
typeof define === 'function' && define.amd ? define(['exports'], factory) : |
| 206 |
(factory((global.Inferno = global.Inferno || {}))); |
| 207 |
}(this, (function (exports) { 'use strict'; |
| 208 |
|
| 209 |
var NO_OP = '$NO_OP'; |
| 210 |
var ERROR_MSG = 'a runtime error occured! Use Inferno in development environment to find the error.'; |
| 211 |
var isBrowser = typeof window !== 'undefined' && window.document; |
| 212 |
|
| 213 |
// this is MUCH faster than .constructor === Array and instanceof Array |
| 214 |
// in Node 7 and the later versions of V8, slower in older versions though |
| 215 |
var isArray = Array.isArray; |
| 216 |
function isStatefulComponent(o) { |
| 217 |
return !isUndefined(o.prototype) && !isUndefined(o.prototype.render); |
| 218 |
} |
| 219 |
function isStringOrNumber(obj) { |
| 220 |
return isString(obj) || isNumber(obj); |
| 221 |
} |
| 222 |
function isNullOrUndef(obj) { |
| 223 |
return isUndefined(obj) || isNull(obj); |
| 224 |
} |
| 225 |
function isInvalid(obj) { |
| 226 |
return isNull(obj) || obj === false || isTrue(obj) || isUndefined(obj); |
| 227 |
} |
| 228 |
function isFunction(obj) { |
| 229 |
return typeof obj === 'function'; |
| 230 |
} |
| 231 |
function isAttrAnEvent(attr) { |
| 232 |
return attr[0] === 'o' && attr[1] === 'n' && attr.length > 3; |
| 233 |
} |
| 234 |
function isString(obj) { |
| 235 |
return typeof obj === 'string'; |
| 236 |
} |
| 237 |
function isNumber(obj) { |
| 238 |
return typeof obj === 'number'; |
| 239 |
} |
| 240 |
function isNull(obj) { |
| 241 |
return obj === null; |
| 242 |
} |
| 243 |
function isTrue(obj) { |
| 244 |
return obj === true; |
| 245 |
} |
| 246 |
function isUndefined(obj) { |
| 247 |
return obj === undefined; |
| 248 |
} |
| 249 |
function isObject(o) { |
| 250 |
return typeof o === 'object'; |
| 251 |
} |
| 252 |
function throwError(message) { |
| 253 |
if (!message) { |
| 254 |
message = ERROR_MSG; |
| 255 |
} |
| 256 |
throw new Error(("Inferno Error: " + message)); |
| 257 |
} |
| 258 |
function warning(condition, message) { |
| 259 |
if (!condition) { |
| 260 |
console.error(message); |
| 261 |
} |
| 262 |
} |
| 263 |
var EMPTY_OBJ = {}; |
| 264 |
|
| 265 |
function cloneVNode(vNodeToClone, props) { |
| 266 |
var _children = [], len = arguments.length - 2; |
| 267 |
while ( len-- > 0 ) _children[ len ] = arguments[ len + 2 ]; |
| 268 |
|
| 269 |
var children = _children; |
| 270 |
if (_children.length > 0 && !isNull(_children[0])) { |
| 271 |
if (!props) { |
| 272 |
props = {}; |
| 273 |
} |
| 274 |
if (_children.length === 1) { |
| 275 |
children = _children[0]; |
| 276 |
} |
| 277 |
if (isUndefined(props.children)) { |
| 278 |
props.children = children; |
| 279 |
} |
| 280 |
else { |
| 281 |
if (isArray(children)) { |
| 282 |
if (isArray(props.children)) { |
| 283 |
props.children = props.children.concat(children); |
| 284 |
} |
| 285 |
else { |
| 286 |
props.children = [props.children].concat(children); |
| 287 |
} |
| 288 |
} |
| 289 |
else { |
| 290 |
if (isArray(props.children)) { |
| 291 |
props.children.push(children); |
| 292 |
} |
| 293 |
else { |
| 294 |
props.children = [props.children]; |
| 295 |
props.children.push(children); |
| 296 |
} |
| 297 |
} |
| 298 |
} |
| 299 |
} |
| 300 |
children = null; |
| 301 |
var flags = vNodeToClone.flags; |
| 302 |
var events = vNodeToClone.events || (props && props.events) || null; |
| 303 |
var newVNode; |
| 304 |
if (isArray(vNodeToClone)) { |
| 305 |
newVNode = vNodeToClone.map(function (vNode) { return cloneVNode(vNode); }); |
| 306 |
} |
| 307 |
else if (isNullOrUndef(props) && isNullOrUndef(children)) { |
| 308 |
newVNode = Object.assign({}, vNodeToClone); |
| 309 |
} |
| 310 |
else { |
| 311 |
var key = !isNullOrUndef(vNodeToClone.key) ? vNodeToClone.key : props.key; |
| 312 |
var ref = vNodeToClone.ref || props.ref; |
| 313 |
if (flags & 28 /* Component */) { |
| 314 |
newVNode = createVNode(flags, vNodeToClone.type, Object.assign({}, vNodeToClone.props, props), null, events, key, ref, true); |
| 315 |
} |
| 316 |
else if (flags & 3970 /* Element */) { |
| 317 |
children = (props && props.children) || vNodeToClone.children; |
| 318 |
newVNode = createVNode(flags, vNodeToClone.type, Object.assign({}, vNodeToClone.props, props), children, events, key, ref, !children); |
| 319 |
} |
| 320 |
} |
| 321 |
if (flags & 28 /* Component */) { |
| 322 |
var newProps = newVNode.props; |
| 323 |
if (newProps) { |
| 324 |
var newChildren = newProps.children; |
| 325 |
// we need to also clone component children that are in props |
| 326 |
// as the children may also have been hoisted |
| 327 |
if (newChildren) { |
| 328 |
if (isArray(newChildren)) { |
| 329 |
for (var i = 0; i < newChildren.length; i++) { |
| 330 |
var child = newChildren[i]; |
| 331 |
if (!isInvalid(child) && isVNode(child)) { |
| 332 |
newProps.children[i] = cloneVNode(child); |
| 333 |
} |
| 334 |
} |
| 335 |
} |
| 336 |
else if (isVNode(newChildren)) { |
| 337 |
newProps.children = cloneVNode(newChildren); |
| 338 |
} |
| 339 |
} |
| 340 |
} |
| 341 |
newVNode.children = null; |
| 342 |
} |
| 343 |
newVNode.dom = null; |
| 344 |
return newVNode; |
| 345 |
} |
| 346 |
|
| 347 |
function _normalizeVNodes(nodes, result, i) { |
| 348 |
for (; i < nodes.length; i++) { |
| 349 |
var n = nodes[i]; |
| 350 |
if (!isInvalid(n)) { |
| 351 |
if (Array.isArray(n)) { |
| 352 |
_normalizeVNodes(n, result, 0); |
| 353 |
} |
| 354 |
else { |
| 355 |
if (isStringOrNumber(n)) { |
| 356 |
n = createTextVNode(n); |
| 357 |
} |
| 358 |
else if (isVNode(n) && n.dom) { |
| 359 |
n = cloneVNode(n); |
| 360 |
} |
| 361 |
result.push(n); |
| 362 |
} |
| 363 |
} |
| 364 |
} |
| 365 |
} |
| 366 |
function normalizeVNodes(nodes) { |
| 367 |
var newNodes; |
| 368 |
// we assign $ which basically means we've flagged this array for future note |
| 369 |
// if it comes back again, we need to clone it, as people are using it |
| 370 |
// in an immutable way |
| 371 |
// tslint:disable |
| 372 |
if (nodes['$']) { |
| 373 |
nodes = nodes.slice(); |
| 374 |
} |
| 375 |
else { |
| 376 |
nodes['$'] = true; |
| 377 |
} |
| 378 |
// tslint:enable |
| 379 |
for (var i = 0; i < nodes.length; i++) { |
| 380 |
var n = nodes[i]; |
| 381 |
if (isInvalid(n)) { |
| 382 |
if (!newNodes) { |
| 383 |
newNodes = nodes.slice(0, i); |
| 384 |
} |
| 385 |
newNodes.push(n); |
| 386 |
} |
| 387 |
else if (Array.isArray(n)) { |
| 388 |
var result = (newNodes || nodes).slice(0, i); |
| 389 |
_normalizeVNodes(nodes, result, i); |
| 390 |
return result; |
| 391 |
} |
| 392 |
else if (isStringOrNumber(n)) { |
| 393 |
if (!newNodes) { |
| 394 |
newNodes = nodes.slice(0, i); |
| 395 |
} |
| 396 |
newNodes.push(createTextVNode(n)); |
| 397 |
} |
| 398 |
else if (isVNode(n) && n.dom) { |
| 399 |
if (!newNodes) { |
| 400 |
newNodes = nodes.slice(0, i); |
| 401 |
} |
| 402 |
newNodes.push(cloneVNode(n)); |
| 403 |
} |
| 404 |
else if (newNodes) { |
| 405 |
newNodes.push(cloneVNode(n)); |
| 406 |
} |
| 407 |
} |
| 408 |
return newNodes || nodes; |
| 409 |
} |
| 410 |
function normalizeChildren(children) { |
| 411 |
if (isArray(children)) { |
| 412 |
return normalizeVNodes(children); |
| 413 |
} |
| 414 |
else if (isVNode(children) && children.dom) { |
| 415 |
return cloneVNode(children); |
| 416 |
} |
| 417 |
return children; |
| 418 |
} |
| 419 |
function normalizeProps(vNode, props, children) { |
| 420 |
if (!(vNode.flags & 28 /* Component */) && isNullOrUndef(children) && !isNullOrUndef(props.children)) { |
| 421 |
vNode.children = props.children; |
| 422 |
} |
| 423 |
if (props.ref) { |
| 424 |
vNode.ref = props.ref; |
| 425 |
} |
| 426 |
if (props.events) { |
| 427 |
vNode.events = props.events; |
| 428 |
} |
| 429 |
if (!isNullOrUndef(props.key)) { |
| 430 |
vNode.key = props.key; |
| 431 |
} |
| 432 |
} |
| 433 |
function normalize(vNode) { |
| 434 |
var props = vNode.props; |
| 435 |
var children = vNode.children; |
| 436 |
// convert a wrongly created type back to element |
| 437 |
if (isString(vNode.type) && (vNode.flags & 28 /* Component */)) { |
| 438 |
vNode.flags = 3970 /* Element */; |
| 439 |
} |
| 440 |
if (props) { |
| 441 |
normalizeProps(vNode, props, children); |
| 442 |
} |
| 443 |
if (!isInvalid(children)) { |
| 444 |
vNode.children = normalizeChildren(children); |
| 445 |
} |
| 446 |
if (props && !isInvalid(props.children)) { |
| 447 |
props.children = normalizeChildren(props.children); |
| 448 |
} |
| 449 |
} |
| 450 |
function createVNode(flags, type, props, children, events, key, ref, noNormalise) { |
| 451 |
if (flags & 16 /* ComponentUnknown */) { |
| 452 |
flags = isStatefulComponent(type) ? 4 /* ComponentClass */ : 8 /* ComponentFunction */; |
| 453 |
} |
| 454 |
var vNode = { |
| 455 |
children: isUndefined(children) ? null : children, |
| 456 |
dom: null, |
| 457 |
events: events || null, |
| 458 |
flags: flags || 0, |
| 459 |
key: key === undefined ? null : key, |
| 460 |
props: props || null, |
| 461 |
ref: ref || null, |
| 462 |
type: type |
| 463 |
}; |
| 464 |
if (!noNormalise) { |
| 465 |
normalize(vNode); |
| 466 |
} |
| 467 |
return vNode; |
| 468 |
} |
| 469 |
function createVoidVNode() { |
| 470 |
return createVNode(4096 /* Void */); |
| 471 |
} |
| 472 |
function createTextVNode(text) { |
| 473 |
return createVNode(1 /* Text */, null, null, text); |
| 474 |
} |
| 475 |
function isVNode(o) { |
| 476 |
return !!o.flags; |
| 477 |
} |
| 478 |
|
| 479 |
var devToolsStatus = { |
| 480 |
connected: false |
| 481 |
}; |
| 482 |
var internalIncrementer = { |
| 483 |
id: 0 |
| 484 |
}; |
| 485 |
var componentIdMap = new Map(); |
| 486 |
function getIncrementalId() { |
| 487 |
return internalIncrementer.id++; |
| 488 |
} |
| 489 |
function sendToDevTools(global, data) { |
| 490 |
var event = new CustomEvent('inferno.client.message', { |
| 491 |
detail: JSON.stringify(data, function (key, val) { |
| 492 |
if (!isNull(val) && !isUndefined(val)) { |
| 493 |
if (key === '_vComponent' || !isUndefined(val.nodeType)) { |
| 494 |
return; |
| 495 |
} |
| 496 |
else if (isFunction(val)) { |
| 497 |
return ("$$f:" + (val.name)); |
| 498 |
} |
| 499 |
} |
| 500 |
return val; |
| 501 |
}) |
| 502 |
}); |
| 503 |
global.dispatchEvent(event); |
| 504 |
} |
| 505 |
function rerenderRoots() { |
| 506 |
for (var i = 0; i < roots.length; i++) { |
| 507 |
var root = roots[i]; |
| 508 |
render(root.input, root.dom); |
| 509 |
} |
| 510 |
} |
| 511 |
function initDevToolsHooks(global) { |
| 512 |
global.__INFERNO_DEVTOOLS_GLOBAL_HOOK__ = roots; |
| 513 |
global.addEventListener('inferno.devtools.message', function (message) { |
| 514 |
var detail = JSON.parse(message.detail); |
| 515 |
var type = detail.type; |
| 516 |
switch (type) { |
| 517 |
case 'get-roots': |
| 518 |
if (!devToolsStatus.connected) { |
| 519 |
devToolsStatus.connected = true; |
| 520 |
rerenderRoots(); |
| 521 |
sendRoots(global); |
| 522 |
} |
| 523 |
break; |
| 524 |
default: |
| 525 |
// TODO:? |
| 526 |
break; |
| 527 |
} |
| 528 |
}); |
| 529 |
} |
| 530 |
function sendRoots(global) { |
| 531 |
sendToDevTools(global, { type: 'roots', data: roots }); |
| 532 |
} |
| 533 |
|
| 534 |
var Lifecycle = function Lifecycle() { |
| 535 |
this.listeners = []; |
| 536 |
this.fastUnmount = true; |
| 537 |
}; |
| 538 |
Lifecycle.prototype.addListener = function addListener (callback) { |
| 539 |
this.listeners.push(callback); |
| 540 |
}; |
| 541 |
Lifecycle.prototype.trigger = function trigger () { |
| 542 |
var this$1 = this; |
| 543 |
|
| 544 |
for (var i = 0; i < this.listeners.length; i++) { |
| 545 |
this$1.listeners[i](); |
| 546 |
} |
| 547 |
}; |
| 548 |
|
| 549 |
function constructDefaults(string, object, value) { |
| 550 |
/* eslint no-return-assign: 0 */ |
| 551 |
string.split(',').forEach(function (i) { return object[i] = value; }); |
| 552 |
} |
| 553 |
var xlinkNS = 'http://www.w3.org/1999/xlink'; |
| 554 |
var xmlNS = 'http://www.w3.org/XML/1998/namespace'; |
| 555 |
var svgNS = 'http://www.w3.org/2000/svg'; |
| 556 |
var strictProps = {}; |
| 557 |
var booleanProps = {}; |
| 558 |
var namespaces = {}; |
| 559 |
var isUnitlessNumber = {}; |
| 560 |
var skipProps = {}; |
| 561 |
var dehyphenProps = { |
| 562 |
textAnchor: 'text-anchor' |
| 563 |
}; |
| 564 |
var delegatedProps = {}; |
| 565 |
constructDefaults('xlink:href,xlink:arcrole,xlink:actuate,xlink:role,xlink:titlef,xlink:type', namespaces, xlinkNS); |
| 566 |
constructDefaults('xml:base,xml:lang,xml:space', namespaces, xmlNS); |
| 567 |
constructDefaults('volume,defaultValue,defaultChecked', strictProps, true); |
| 568 |
constructDefaults('children,ref,key,selected,checked,value,multiple', skipProps, true); |
| 569 |
constructDefaults('onClick,onMouseDown,onMouseUp,onMouseMove', delegatedProps, true); |
| 570 |
constructDefaults('muted,scoped,loop,open,checked,default,capture,disabled,readonly,required,autoplay,controls,seamless,reversed,allowfullscreen,novalidate', booleanProps, true); |
| 571 |
constructDefaults('animationIterationCount,borderImageOutset,borderImageSlice,borderImageWidth,boxFlex,boxFlexGroup,boxOrdinalGroup,columnCount,flex,flexGrow,flexPositive,flexShrink,flexNegative,flexOrder,gridRow,gridColumn,fontWeight,lineClamp,lineHeight,opacity,order,orphans,tabSize,widows,zIndex,zoom,fillOpacity,floodOpacity,stopOpacity,strokeDasharray,strokeDashoffset,strokeMiterlimit,strokeOpacity,strokeWidth,', isUnitlessNumber, true); |
| 572 |
|
| 573 |
var delegatedEvents = new Map(); |
| 574 |
function handleEvent(name, lastEvent, nextEvent, dom) { |
| 575 |
var delegatedRoots = delegatedEvents.get(name); |
| 576 |
if (nextEvent) { |
| 577 |
if (!delegatedRoots) { |
| 578 |
delegatedRoots = { items: new Map(), count: 0, docEvent: null }; |
| 579 |
var docEvent = attachEventToDocument(name, delegatedRoots); |
| 580 |
delegatedRoots.docEvent = docEvent; |
| 581 |
delegatedEvents.set(name, delegatedRoots); |
| 582 |
} |
| 583 |
if (!lastEvent) { |
| 584 |
delegatedRoots.count++; |
| 585 |
} |
| 586 |
delegatedRoots.items.set(dom, nextEvent); |
| 587 |
} |
| 588 |
else if (delegatedRoots) { |
| 589 |
if (delegatedRoots.items.has(dom)) { |
| 590 |
delegatedRoots.count--; |
| 591 |
delegatedRoots.items.delete(dom); |
| 592 |
if (delegatedRoots.count === 0) { |
| 593 |
document.removeEventListener(normalizeEventName(name), delegatedRoots.docEvent); |
| 594 |
delegatedEvents.delete(name); |
| 595 |
} |
| 596 |
} |
| 597 |
} |
| 598 |
} |
| 599 |
function dispatchEvent(event, dom, items, count, eventData) { |
| 600 |
var eventsToTrigger = items.get(dom); |
| 601 |
if (eventsToTrigger) { |
| 602 |
count--; |
| 603 |
// linkEvent object |
| 604 |
eventData.dom = dom; |
| 605 |
if (eventsToTrigger.event) { |
| 606 |
eventsToTrigger.event(eventsToTrigger.data, event); |
| 607 |
} |
| 608 |
else { |
| 609 |
eventsToTrigger(event); |
| 610 |
} |
| 611 |
if (eventData.stopPropagation) { |
| 612 |
return; |
| 613 |
} |
| 614 |
} |
| 615 |
var parentDom = dom.parentNode; |
| 616 |
if (count > 0 && (parentDom || parentDom === document.body)) { |
| 617 |
dispatchEvent(event, parentDom, items, count, eventData); |
| 618 |
} |
| 619 |
} |
| 620 |
function normalizeEventName(name) { |
| 621 |
return name.substr(2).toLowerCase(); |
| 622 |
} |
| 623 |
function attachEventToDocument(name, delegatedRoots) { |
| 624 |
var docEvent = function (event) { |
| 625 |
var eventData = { |
| 626 |
stopPropagation: false, |
| 627 |
dom: document |
| 628 |
}; |
| 629 |
// we have to do this as some browsers recycle the same Event between calls |
| 630 |
// so we need to make the property configurable |
| 631 |
Object.defineProperty(event, 'currentTarget', { |
| 632 |
configurable: true, |
| 633 |
get: function get() { |
| 634 |
return eventData.dom; |
| 635 |
} |
| 636 |
}); |
| 637 |
event.stopPropagation = function () { |
| 638 |
eventData.stopPropagation = true; |
| 639 |
}; |
| 640 |
var count = delegatedRoots.count; |
| 641 |
if (count > 0) { |
| 642 |
dispatchEvent(event, event.target, delegatedRoots.items, count, eventData); |
| 643 |
} |
| 644 |
}; |
| 645 |
document.addEventListener(normalizeEventName(name), docEvent); |
| 646 |
return docEvent; |
| 647 |
} |
| 648 |
|
| 649 |
function isCheckedType(type) { |
| 650 |
return type === 'checkbox' || type === 'radio'; |
| 651 |
} |
| 652 |
function isControlled(props) { |
| 653 |
var usesChecked = isCheckedType(props.type); |
| 654 |
return usesChecked ? !isNullOrUndef(props.checked) : !isNullOrUndef(props.value); |
| 655 |
} |
| 656 |
function onTextInputChange(e) { |
| 657 |
var vNode = this.vNode; |
| 658 |
var events = vNode.events || EMPTY_OBJ; |
| 659 |
var dom = vNode.dom; |
| 660 |
if (events.onInput) { |
| 661 |
events.onInput(e); |
| 662 |
} |
| 663 |
else if (events.oninput) { |
| 664 |
events.oninput(e); |
| 665 |
} |
| 666 |
// the user may have updated the vNode from the above onInput events |
| 667 |
// so we need to get it from the context of `this` again |
| 668 |
applyValue(this.vNode, dom); |
| 669 |
} |
| 670 |
function onCheckboxChange(e) { |
| 671 |
var vNode = this.vNode; |
| 672 |
var events = vNode.events || EMPTY_OBJ; |
| 673 |
var dom = vNode.dom; |
| 674 |
if (events.onClick) { |
| 675 |
events.onClick(e); |
| 676 |
} |
| 677 |
else if (events.onclick) { |
| 678 |
events.onclick(e); |
| 679 |
} |
| 680 |
// the user may have updated the vNode from the above onClick events |
| 681 |
// so we need to get it from the context of `this` again |
| 682 |
applyValue(this.vNode, dom); |
| 683 |
} |
| 684 |
function handleAssociatedRadioInputs(name) { |
| 685 |
var inputs = document.querySelectorAll(("input[type=\"radio\"][name=\"" + name + "\"]")); |
| 686 |
[].forEach.call(inputs, function (dom) { |
| 687 |
var inputWrapper = wrappers.get(dom); |
| 688 |
if (inputWrapper) { |
| 689 |
var props = inputWrapper.vNode.props; |
| 690 |
if (props) { |
| 691 |
dom.checked = inputWrapper.vNode.props.checked; |
| 692 |
} |
| 693 |
} |
| 694 |
}); |
| 695 |
} |
| 696 |
function processInput(vNode, dom) { |
| 697 |
var props = vNode.props || EMPTY_OBJ; |
| 698 |
applyValue(vNode, dom); |
| 699 |
if (isControlled(props)) { |
| 700 |
var inputWrapper = wrappers.get(dom); |
| 701 |
if (!inputWrapper) { |
| 702 |
inputWrapper = { |
| 703 |
vNode: vNode |
| 704 |
}; |
| 705 |
if (isCheckedType(props.type)) { |
| 706 |
dom.onclick = onCheckboxChange.bind(inputWrapper); |
| 707 |
dom.onclick.wrapped = true; |
| 708 |
} |
| 709 |
else { |
| 710 |
dom.oninput = onTextInputChange.bind(inputWrapper); |
| 711 |
dom.oninput.wrapped = true; |
| 712 |
} |
| 713 |
wrappers.set(dom, inputWrapper); |
| 714 |
} |
| 715 |
inputWrapper.vNode = vNode; |
| 716 |
} |
| 717 |
} |
| 718 |
function applyValue(vNode, dom) { |
| 719 |
var props = vNode.props || EMPTY_OBJ; |
| 720 |
var type = props.type; |
| 721 |
var value = props.value; |
| 722 |
var checked = props.checked; |
| 723 |
if (type !== dom.type && type) { |
| 724 |
dom.type = type; |
| 725 |
} |
| 726 |
if (props.multiple !== dom.multiple) { |
| 727 |
dom.multiple = props.multiple; |
| 728 |
} |
| 729 |
if (isCheckedType(type)) { |
| 730 |
if (!isNullOrUndef(value)) { |
| 731 |
dom.value = value; |
| 732 |
} |
| 733 |
dom.checked = checked; |
| 734 |
if (type === 'radio' && props.name) { |
| 735 |
handleAssociatedRadioInputs(props.name); |
| 736 |
} |
| 737 |
} |
| 738 |
else { |
| 739 |
if (!isNullOrUndef(value) && dom.value !== value) { |
| 740 |
dom.value = value; |
| 741 |
} |
| 742 |
else if (!isNullOrUndef(checked)) { |
| 743 |
dom.checked = checked; |
| 744 |
} |
| 745 |
} |
| 746 |
} |
| 747 |
|
| 748 |
function isControlled$1(props) { |
| 749 |
return !isNullOrUndef(props.value); |
| 750 |
} |
| 751 |
function updateChildOption(vNode, value) { |
| 752 |
var props = vNode.props || EMPTY_OBJ; |
| 753 |
var dom = vNode.dom; |
| 754 |
// we do this as multiple may have changed |
| 755 |
dom.value = props.value; |
| 756 |
if ((isArray(value) && value.indexOf(props.value) !== -1) || props.value === value) { |
| 757 |
dom.selected = true; |
| 758 |
} |
| 759 |
else { |
| 760 |
dom.selected = props.selected || false; |
| 761 |
} |
| 762 |
} |
| 763 |
function onSelectChange(e) { |
| 764 |
var vNode = this.vNode; |
| 765 |
var events = vNode.events || EMPTY_OBJ; |
| 766 |
var dom = vNode.dom; |
| 767 |
if (events.onChange) { |
| 768 |
events.onChange(e); |
| 769 |
} |
| 770 |
else if (events.onchange) { |
| 771 |
events.onchange(e); |
| 772 |
} |
| 773 |
// the user may have updated the vNode from the above onChange events |
| 774 |
// so we need to get it from the context of `this` again |
| 775 |
applyValue$1(this.vNode, dom); |
| 776 |
} |
| 777 |
function processSelect(vNode, dom) { |
| 778 |
var props = vNode.props || EMPTY_OBJ; |
| 779 |
applyValue$1(vNode, dom); |
| 780 |
if (isControlled$1(props)) { |
| 781 |
var selectWrapper = wrappers.get(dom); |
| 782 |
if (!selectWrapper) { |
| 783 |
selectWrapper = { |
| 784 |
vNode: vNode |
| 785 |
}; |
| 786 |
dom.onchange = onSelectChange.bind(selectWrapper); |
| 787 |
dom.onchange.wrapped = true; |
| 788 |
wrappers.set(dom, selectWrapper); |
| 789 |
} |
| 790 |
selectWrapper.vNode = vNode; |
| 791 |
} |
| 792 |
} |
| 793 |
function applyValue$1(vNode, dom) { |
| 794 |
var props = vNode.props || EMPTY_OBJ; |
| 795 |
if (props.multiple !== dom.multiple) { |
| 796 |
dom.multiple = props.multiple; |
| 797 |
} |
| 798 |
var children = vNode.children; |
| 799 |
var value = props.value; |
| 800 |
if (isArray(children)) { |
| 801 |
for (var i = 0; i < children.length; i++) { |
| 802 |
updateChildOption(children[i], value); |
| 803 |
} |
| 804 |
} |
| 805 |
else if (isVNode(children)) { |
| 806 |
updateChildOption(children, value); |
| 807 |
} |
| 808 |
} |
| 809 |
|
| 810 |
function isControlled$2(props) { |
| 811 |
return !isNullOrUndef(props.value); |
| 812 |
} |
| 813 |
function onTextareaInputChange(e) { |
| 814 |
var vNode = this.vNode; |
| 815 |
var events = vNode.events || EMPTY_OBJ; |
| 816 |
var dom = vNode.dom; |
| 817 |
if (events.onInput) { |
| 818 |
events.onInput(e); |
| 819 |
} |
| 820 |
else if (events.oninput) { |
| 821 |
events.oninput(e); |
| 822 |
} |
| 823 |
// the user may have updated the vNode from the above onInput events |
| 824 |
// so we need to get it from the context of `this` again |
| 825 |
applyValue$2(this.vNode, dom); |
| 826 |
} |
| 827 |
function processTextarea(vNode, dom) { |
| 828 |
var props = vNode.props || EMPTY_OBJ; |
| 829 |
applyValue$2(vNode, dom); |
| 830 |
var textareaWrapper = wrappers.get(dom); |
| 831 |
if (isControlled$2(props)) { |
| 832 |
if (!textareaWrapper) { |
| 833 |
textareaWrapper = { |
| 834 |
vNode: vNode |
| 835 |
}; |
| 836 |
dom.oninput = onTextareaInputChange.bind(textareaWrapper); |
| 837 |
dom.oninput.wrapped = true; |
| 838 |
wrappers.set(dom, textareaWrapper); |
| 839 |
} |
| 840 |
textareaWrapper.vNode = vNode; |
| 841 |
} |
| 842 |
} |
| 843 |
function applyValue$2(vNode, dom) { |
| 844 |
var props = vNode.props || EMPTY_OBJ; |
| 845 |
var value = props.value; |
| 846 |
if (dom.value !== value) { |
| 847 |
dom.value = value; |
| 848 |
} |
| 849 |
} |
| 850 |
|
| 851 |
var wrappers = new Map(); |
| 852 |
function processElement(flags, vNode, dom) { |
| 853 |
if (flags & 512 /* InputElement */) { |
| 854 |
processInput(vNode, dom); |
| 855 |
} |
| 856 |
else if (flags & 2048 /* SelectElement */) { |
| 857 |
processSelect(vNode, dom); |
| 858 |
} |
| 859 |
else if (flags & 1024 /* TextareaElement */) { |
| 860 |
processTextarea(vNode, dom); |
| 861 |
} |
| 862 |
} |
| 863 |
|
| 864 |
function unmount(vNode, parentDom, lifecycle, canRecycle, shallowUnmount, isRecycling) { |
| 865 |
var flags = vNode.flags; |
| 866 |
if (flags & 28 /* Component */) { |
| 867 |
unmountComponent(vNode, parentDom, lifecycle, canRecycle, shallowUnmount, isRecycling); |
| 868 |
} |
| 869 |
else if (flags & 3970 /* Element */) { |
| 870 |
unmountElement(vNode, parentDom, lifecycle, canRecycle, shallowUnmount, isRecycling); |
| 871 |
} |
| 872 |
else if (flags & (1 /* Text */ | 4096 /* Void */)) { |
| 873 |
unmountVoidOrText(vNode, parentDom); |
| 874 |
} |
| 875 |
} |
| 876 |
function unmountVoidOrText(vNode, parentDom) { |
| 877 |
if (parentDom) { |
| 878 |
removeChild(parentDom, vNode.dom); |
| 879 |
} |
| 880 |
} |
| 881 |
function unmountComponent(vNode, parentDom, lifecycle, canRecycle, shallowUnmount, isRecycling) { |
| 882 |
var instance = vNode.children; |
| 883 |
var flags = vNode.flags; |
| 884 |
var isStatefulComponent$$1 = flags & 4; |
| 885 |
var ref = vNode.ref; |
| 886 |
var dom = vNode.dom; |
| 887 |
if (!isRecycling) { |
| 888 |
if (!shallowUnmount) { |
| 889 |
if (isStatefulComponent$$1) { |
| 890 |
var subLifecycle = instance._lifecycle; |
| 891 |
if (!subLifecycle.fastUnmount) { |
| 892 |
unmount(instance._lastInput, null, lifecycle, false, shallowUnmount, isRecycling); |
| 893 |
} |
| 894 |
} |
| 895 |
else { |
| 896 |
if (!lifecycle.fastUnmount) { |
| 897 |
unmount(instance, null, lifecycle, false, shallowUnmount, isRecycling); |
| 898 |
} |
| 899 |
} |
| 900 |
} |
| 901 |
if (isStatefulComponent$$1) { |
| 902 |
instance._ignoreSetState = true; |
| 903 |
instance.componentWillUnmount(); |
| 904 |
if (ref && !isRecycling) { |
| 905 |
ref(null); |
| 906 |
} |
| 907 |
instance._unmounted = true; |
| 908 |
findDOMNodeEnabled && componentToDOMNodeMap.delete(instance); |
| 909 |
} |
| 910 |
else if (!isNullOrUndef(ref)) { |
| 911 |
if (!isNullOrUndef(ref.onComponentWillUnmount)) { |
| 912 |
ref.onComponentWillUnmount(dom); |
| 913 |
} |
| 914 |
} |
| 915 |
} |
| 916 |
if (parentDom) { |
| 917 |
var lastInput = instance._lastInput; |
| 918 |
if (isNullOrUndef(lastInput)) { |
| 919 |
lastInput = instance; |
| 920 |
} |
| 921 |
removeChild(parentDom, dom); |
| 922 |
} |
| 923 |
if (recyclingEnabled && !isStatefulComponent$$1 && (parentDom || canRecycle)) { |
| 924 |
poolComponent(vNode); |
| 925 |
} |
| 926 |
} |
| 927 |
function unmountElement(vNode, parentDom, lifecycle, canRecycle, shallowUnmount, isRecycling) { |
| 928 |
var dom = vNode.dom; |
| 929 |
var ref = vNode.ref; |
| 930 |
var events = vNode.events; |
| 931 |
if (!shallowUnmount && !lifecycle.fastUnmount) { |
| 932 |
if (ref && !isRecycling) { |
| 933 |
unmountRef(ref); |
| 934 |
} |
| 935 |
var children = vNode.children; |
| 936 |
if (!isNullOrUndef(children)) { |
| 937 |
unmountChildren$1(children, lifecycle, shallowUnmount, isRecycling); |
| 938 |
} |
| 939 |
} |
| 940 |
if (!isNull(events)) { |
| 941 |
for (var name in events) { |
| 942 |
// do not add a hasOwnProperty check here, it affects performance |
| 943 |
patchEvent(name, events[name], null, dom, lifecycle); |
| 944 |
events[name] = null; |
| 945 |
} |
| 946 |
} |
| 947 |
if (parentDom) { |
| 948 |
removeChild(parentDom, dom); |
| 949 |
} |
| 950 |
if (recyclingEnabled && (parentDom || canRecycle)) { |
| 951 |
poolElement(vNode); |
| 952 |
} |
| 953 |
} |
| 954 |
function unmountChildren$1(children, lifecycle, shallowUnmount, isRecycling) { |
| 955 |
if (isArray(children)) { |
| 956 |
for (var i = 0; i < children.length; i++) { |
| 957 |
var child = children[i]; |
| 958 |
if (!isInvalid(child) && isObject(child)) { |
| 959 |
unmount(child, null, lifecycle, false, shallowUnmount, isRecycling); |
| 960 |
} |
| 961 |
} |
| 962 |
} |
| 963 |
else if (isObject(children)) { |
| 964 |
unmount(children, null, lifecycle, false, shallowUnmount, isRecycling); |
| 965 |
} |
| 966 |
} |
| 967 |
function unmountRef(ref) { |
| 968 |
if (isFunction(ref)) { |
| 969 |
ref(null); |
| 970 |
} |
| 971 |
else { |
| 972 |
if (isInvalid(ref)) { |
| 973 |
return; |
| 974 |
} |
| 975 |
if (false) { |
| 976 |
throwError('string "refs" are not supported in Inferno 1.0. Use callback "refs" instead.'); |
| 977 |
} |
| 978 |
throwError(); |
| 979 |
} |
| 980 |
} |
| 981 |
|
| 982 |
function patch(lastVNode, nextVNode, parentDom, lifecycle, context, isSVG, isRecycling) { |
| 983 |
if (lastVNode !== nextVNode) { |
| 984 |
var lastFlags = lastVNode.flags; |
| 985 |
var nextFlags = nextVNode.flags; |
| 986 |
if (nextFlags & 28 /* Component */) { |
| 987 |
if (lastFlags & 28 /* Component */) { |
| 988 |
patchComponent(lastVNode, nextVNode, parentDom, lifecycle, context, isSVG, nextFlags & 4 /* ComponentClass */, isRecycling); |
| 989 |
} |
| 990 |
else { |
| 991 |
replaceVNode(parentDom, mountComponent(nextVNode, null, lifecycle, context, isSVG, nextFlags & 4 /* ComponentClass */), lastVNode, lifecycle, isRecycling); |
| 992 |
} |
| 993 |
} |
| 994 |
else if (nextFlags & 3970 /* Element */) { |
| 995 |
if (lastFlags & 3970 /* Element */) { |
| 996 |
patchElement(lastVNode, nextVNode, parentDom, lifecycle, context, isSVG, isRecycling); |
| 997 |
} |
| 998 |
else { |
| 999 |
replaceVNode(parentDom, mountElement(nextVNode, null, lifecycle, context, isSVG), lastVNode, lifecycle, isRecycling); |
| 1000 |
} |
| 1001 |
} |
| 1002 |
else if (nextFlags & 1 /* Text */) { |
| 1003 |
if (lastFlags & 1 /* Text */) { |
| 1004 |
patchText(lastVNode, nextVNode); |
| 1005 |
} |
| 1006 |
else { |
| 1007 |
replaceVNode(parentDom, mountText(nextVNode, null), lastVNode, lifecycle, isRecycling); |
| 1008 |
} |
| 1009 |
} |
| 1010 |
else if (nextFlags & 4096 /* Void */) { |
| 1011 |
if (lastFlags & 4096 /* Void */) { |
| 1012 |
patchVoid(lastVNode, nextVNode); |
| 1013 |
} |
| 1014 |
else { |
| 1015 |
replaceVNode(parentDom, mountVoid(nextVNode, null), lastVNode, lifecycle, isRecycling); |
| 1016 |
} |
| 1017 |
} |
| 1018 |
else { |
| 1019 |
// Error case: mount new one replacing old one |
| 1020 |
replaceLastChildAndUnmount(lastVNode, nextVNode, parentDom, lifecycle, context, isSVG, isRecycling); |
| 1021 |
} |
| 1022 |
} |
| 1023 |
} |
| 1024 |
function unmountChildren(children, dom, lifecycle, isRecycling) { |
| 1025 |
if (isVNode(children)) { |
| 1026 |
unmount(children, dom, lifecycle, true, false, isRecycling); |
| 1027 |
} |
| 1028 |
else if (isArray(children)) { |
| 1029 |
removeAllChildren(dom, children, lifecycle, false, isRecycling); |
| 1030 |
} |
| 1031 |
else { |
| 1032 |
dom.textContent = ''; |
| 1033 |
} |
| 1034 |
} |
| 1035 |
function patchElement(lastVNode, nextVNode, parentDom, lifecycle, context, isSVG, isRecycling) { |
| 1036 |
var nextTag = nextVNode.type; |
| 1037 |
var lastTag = lastVNode.type; |
| 1038 |
if (lastTag !== nextTag) { |
| 1039 |
replaceWithNewNode(lastVNode, nextVNode, parentDom, lifecycle, context, isSVG, isRecycling); |
| 1040 |
} |
| 1041 |
else { |
| 1042 |
var dom = lastVNode.dom; |
| 1043 |
var lastProps = lastVNode.props; |
| 1044 |
var nextProps = nextVNode.props; |
| 1045 |
var lastChildren = lastVNode.children; |
| 1046 |
var nextChildren = nextVNode.children; |
| 1047 |
var lastFlags = lastVNode.flags; |
| 1048 |
var nextFlags = nextVNode.flags; |
| 1049 |
var lastRef = lastVNode.ref; |
| 1050 |
var nextRef = nextVNode.ref; |
| 1051 |
var lastEvents = lastVNode.events; |
| 1052 |
var nextEvents = nextVNode.events; |
| 1053 |
nextVNode.dom = dom; |
| 1054 |
if (isSVG || (nextFlags & 128 /* SvgElement */)) { |
| 1055 |
isSVG = true; |
| 1056 |
} |
| 1057 |
if (lastChildren !== nextChildren) { |
| 1058 |
patchChildren(lastFlags, nextFlags, lastChildren, nextChildren, dom, lifecycle, context, isSVG, isRecycling); |
| 1059 |
} |
| 1060 |
if (!(nextFlags & 2 /* HtmlElement */)) { |
| 1061 |
processElement(nextFlags, nextVNode, dom); |
| 1062 |
} |
| 1063 |
if (lastProps !== nextProps) { |
| 1064 |
patchProps(lastProps, nextProps, dom, lifecycle, context, isSVG); |
| 1065 |
} |
| 1066 |
if (lastEvents !== nextEvents) { |
| 1067 |
patchEvents(lastEvents, nextEvents, dom, lifecycle); |
| 1068 |
} |
| 1069 |
if (nextRef) { |
| 1070 |
if (lastRef !== nextRef || isRecycling) { |
| 1071 |
mountRef(dom, nextRef, lifecycle); |
| 1072 |
} |
| 1073 |
} |
| 1074 |
} |
| 1075 |
} |
| 1076 |
function patchChildren(lastFlags, nextFlags, lastChildren, nextChildren, dom, lifecycle, context, isSVG, isRecycling) { |
| 1077 |
var patchArray = false; |
| 1078 |
var patchKeyed = false; |
| 1079 |
if (nextFlags & 64 /* HasNonKeyedChildren */) { |
| 1080 |
patchArray = true; |
| 1081 |
} |
| 1082 |
else if ((lastFlags & 32 /* HasKeyedChildren */) && (nextFlags & 32 /* HasKeyedChildren */)) { |
| 1083 |
patchKeyed = true; |
| 1084 |
patchArray = true; |
| 1085 |
} |
| 1086 |
else if (isInvalid(nextChildren)) { |
| 1087 |
unmountChildren(lastChildren, dom, lifecycle, isRecycling); |
| 1088 |
} |
| 1089 |
else if (isInvalid(lastChildren)) { |
| 1090 |
if (isStringOrNumber(nextChildren)) { |
| 1091 |
setTextContent(dom, nextChildren); |
| 1092 |
} |
| 1093 |
else { |
| 1094 |
if (isArray(nextChildren)) { |
| 1095 |
mountArrayChildren(nextChildren, dom, lifecycle, context, isSVG); |
| 1096 |
} |
| 1097 |
else { |
| 1098 |
mount(nextChildren, dom, lifecycle, context, isSVG); |
| 1099 |
} |
| 1100 |
} |
| 1101 |
} |
| 1102 |
else if (isStringOrNumber(nextChildren)) { |
| 1103 |
if (isStringOrNumber(lastChildren)) { |
| 1104 |
updateTextContent(dom, nextChildren); |
| 1105 |
} |
| 1106 |
else { |
| 1107 |
unmountChildren(lastChildren, dom, lifecycle, isRecycling); |
| 1108 |
setTextContent(dom, nextChildren); |
| 1109 |
} |
| 1110 |
} |
| 1111 |
else if (isArray(nextChildren)) { |
| 1112 |
if (isArray(lastChildren)) { |
| 1113 |
patchArray = true; |
| 1114 |
if (isKeyed(lastChildren, nextChildren)) { |
| 1115 |
patchKeyed = true; |
| 1116 |
} |
| 1117 |
} |
| 1118 |
else { |
| 1119 |
unmountChildren(lastChildren, dom, lifecycle, isRecycling); |
| 1120 |
mountArrayChildren(nextChildren, dom, lifecycle, context, isSVG); |
| 1121 |
} |
| 1122 |
} |
| 1123 |
else if (isArray(lastChildren)) { |
| 1124 |
removeAllChildren(dom, lastChildren, lifecycle, false, isRecycling); |
| 1125 |
mount(nextChildren, dom, lifecycle, context, isSVG); |
| 1126 |
} |
| 1127 |
else if (isVNode(nextChildren)) { |
| 1128 |
if (isVNode(lastChildren)) { |
| 1129 |
patch(lastChildren, nextChildren, dom, lifecycle, context, isSVG, isRecycling); |
| 1130 |
} |
| 1131 |
else { |
| 1132 |
unmountChildren(lastChildren, dom, lifecycle, isRecycling); |
| 1133 |
mount(nextChildren, dom, lifecycle, context, isSVG); |
| 1134 |
} |
| 1135 |
} |
| 1136 |
else if (isVNode(lastChildren)) { |
| 1137 |
} |
| 1138 |
else { |
| 1139 |
} |
| 1140 |
if (patchArray) { |
| 1141 |
if (patchKeyed) { |
| 1142 |
patchKeyedChildren(lastChildren, nextChildren, dom, lifecycle, context, isSVG, isRecycling); |
| 1143 |
} |
| 1144 |
else { |
| 1145 |
patchNonKeyedChildren(lastChildren, nextChildren, dom, lifecycle, context, isSVG, isRecycling); |
| 1146 |
} |
| 1147 |
} |
| 1148 |
} |
| 1149 |
function patchComponent(lastVNode, nextVNode, parentDom, lifecycle, context, isSVG, isClass, isRecycling) { |
| 1150 |
var lastType = lastVNode.type; |
| 1151 |
var nextType = nextVNode.type; |
| 1152 |
var nextProps = nextVNode.props || EMPTY_OBJ; |
| 1153 |
var lastKey = lastVNode.key; |
| 1154 |
var nextKey = nextVNode.key; |
| 1155 |
if (lastType !== nextType) { |
| 1156 |
if (isClass) { |
| 1157 |
replaceWithNewNode(lastVNode, nextVNode, parentDom, lifecycle, context, isSVG, isRecycling); |
| 1158 |
} |
| 1159 |
else { |
| 1160 |
var lastInput = lastVNode.children._lastInput || lastVNode.children; |
| 1161 |
var nextInput = createStatelessComponentInput(nextVNode, nextType, nextProps, context); |
| 1162 |
patch(lastInput, nextInput, parentDom, lifecycle, context, isSVG, isRecycling); |
| 1163 |
var dom = nextVNode.dom = nextInput.dom; |
| 1164 |
nextVNode.children = nextInput; |
| 1165 |
mountStatelessComponentCallbacks(nextVNode.ref, dom, lifecycle); |
| 1166 |
unmount(lastVNode, null, lifecycle, false, true, isRecycling); |
| 1167 |
} |
| 1168 |
} |
| 1169 |
else { |
| 1170 |
if (isClass) { |
| 1171 |
if (lastKey !== nextKey) { |
| 1172 |
replaceWithNewNode(lastVNode, nextVNode, parentDom, lifecycle, context, isSVG, isRecycling); |
| 1173 |
return false; |
| 1174 |
} |
| 1175 |
var instance = lastVNode.children; |
| 1176 |
if (instance._unmounted) { |
| 1177 |
if (isNull(parentDom)) { |
| 1178 |
return true; |
| 1179 |
} |
| 1180 |
replaceChild(parentDom, mountComponent(nextVNode, null, lifecycle, context, isSVG, nextVNode.flags & 4 /* ComponentClass */), lastVNode.dom); |
| 1181 |
} |
| 1182 |
else { |
| 1183 |
var defaultProps = nextType.defaultProps; |
| 1184 |
var lastProps = instance.props; |
| 1185 |
if (instance._devToolsStatus.connected && !instance._devToolsId) { |
| 1186 |
componentIdMap.set(instance._devToolsId = getIncrementalId(), instance); |
| 1187 |
} |
| 1188 |
lifecycle.fastUnmount = false; |
| 1189 |
if (!isUndefined(defaultProps)) { |
| 1190 |
copyPropsTo(lastProps, nextProps); |
| 1191 |
nextVNode.props = nextProps; |
| 1192 |
} |
| 1193 |
var lastState = instance.state; |
| 1194 |
var nextState = instance.state; |
| 1195 |
var childContext = instance.getChildContext(); |
| 1196 |
nextVNode.children = instance; |
| 1197 |
instance._isSVG = isSVG; |
| 1198 |
if (!isNullOrUndef(childContext)) { |
| 1199 |
childContext = Object.assign({}, context, childContext); |
| 1200 |
} |
| 1201 |
else { |
| 1202 |
childContext = context; |
| 1203 |
} |
| 1204 |
var lastInput$1 = instance._lastInput; |
| 1205 |
var nextInput$1 = instance._updateComponent(lastState, nextState, lastProps, nextProps, context, false); |
| 1206 |
var didUpdate = true; |
| 1207 |
instance._childContext = childContext; |
| 1208 |
if (isInvalid(nextInput$1)) { |
| 1209 |
nextInput$1 = createVoidVNode(); |
| 1210 |
} |
| 1211 |
else if (isArray(nextInput$1)) { |
| 1212 |
if (false) { |
| 1213 |
throwError('a valid Inferno VNode (or null) must be returned from a component render. You may have returned an array or an invalid object.'); |
| 1214 |
} |
| 1215 |
throwError(); |
| 1216 |
} |
| 1217 |
else if (nextInput$1 === NO_OP) { |
| 1218 |
nextInput$1 = lastInput$1; |
| 1219 |
didUpdate = false; |
| 1220 |
} |
| 1221 |
else if (isObject(nextInput$1) && nextInput$1.dom) { |
| 1222 |
nextInput$1 = cloneVNode(nextInput$1); |
| 1223 |
} |
| 1224 |
if (nextInput$1.flags & 28 /* Component */) { |
| 1225 |
nextInput$1.parentVNode = nextVNode; |
| 1226 |
} |
| 1227 |
else if (lastInput$1.flags & 28 /* Component */) { |
| 1228 |
lastInput$1.parentVNode = nextVNode; |
| 1229 |
} |
| 1230 |
instance._lastInput = nextInput$1; |
| 1231 |
instance._vNode = nextVNode; |
| 1232 |
if (didUpdate) { |
| 1233 |
var fastUnmount = lifecycle.fastUnmount; |
| 1234 |
var subLifecycle = instance._lifecycle; |
| 1235 |
lifecycle.fastUnmount = subLifecycle.fastUnmount; |
| 1236 |
patch(lastInput$1, nextInput$1, parentDom, lifecycle, childContext, isSVG, isRecycling); |
| 1237 |
subLifecycle.fastUnmount = lifecycle.unmount; |
| 1238 |
lifecycle.fastUnmount = fastUnmount; |
| 1239 |
instance.componentDidUpdate(lastProps, lastState); |
| 1240 |
findDOMNodeEnabled && componentToDOMNodeMap.set(instance, nextInput$1.dom); |
| 1241 |
} |
| 1242 |
nextVNode.dom = nextInput$1.dom; |
| 1243 |
} |
| 1244 |
} |
| 1245 |
else { |
| 1246 |
var shouldUpdate = true; |
| 1247 |
var lastProps$1 = lastVNode.props; |
| 1248 |
var nextHooks = nextVNode.ref; |
| 1249 |
var nextHooksDefined = !isNullOrUndef(nextHooks); |
| 1250 |
var lastInput$2 = lastVNode.children; |
| 1251 |
var nextInput$2 = lastInput$2; |
| 1252 |
nextVNode.dom = lastVNode.dom; |
| 1253 |
nextVNode.children = lastInput$2; |
| 1254 |
if (lastKey !== nextKey) { |
| 1255 |
shouldUpdate = true; |
| 1256 |
} |
| 1257 |
else { |
| 1258 |
if (nextHooksDefined && !isNullOrUndef(nextHooks.onComponentShouldUpdate)) { |
| 1259 |
shouldUpdate = nextHooks.onComponentShouldUpdate(lastProps$1, nextProps); |
| 1260 |
} |
| 1261 |
} |
| 1262 |
if (shouldUpdate !== false) { |
| 1263 |
if (nextHooksDefined && !isNullOrUndef(nextHooks.onComponentWillUpdate)) { |
| 1264 |
lifecycle.fastUnmount = false; |
| 1265 |
nextHooks.onComponentWillUpdate(lastProps$1, nextProps); |
| 1266 |
} |
| 1267 |
nextInput$2 = nextType(nextProps, context); |
| 1268 |
if (isInvalid(nextInput$2)) { |
| 1269 |
nextInput$2 = createVoidVNode(); |
| 1270 |
} |
| 1271 |
else if (isArray(nextInput$2)) { |
| 1272 |
if (false) { |
| 1273 |
throwError('a valid Inferno VNode (or null) must be returned from a component render. You may have returned an array or an invalid object.'); |
| 1274 |
} |
| 1275 |
throwError(); |
| 1276 |
} |
| 1277 |
else if (isObject(nextInput$2) && nextInput$2.dom) { |
| 1278 |
nextInput$2 = cloneVNode(nextInput$2); |
| 1279 |
} |
| 1280 |
if (nextInput$2 !== NO_OP) { |
| 1281 |
patch(lastInput$2, nextInput$2, parentDom, lifecycle, context, isSVG, isRecycling); |
| 1282 |
nextVNode.children = nextInput$2; |
| 1283 |
if (nextHooksDefined && !isNullOrUndef(nextHooks.onComponentDidUpdate)) { |
| 1284 |
lifecycle.fastUnmount = false; |
| 1285 |
nextHooks.onComponentDidUpdate(lastProps$1, nextProps); |
| 1286 |
} |
| 1287 |
nextVNode.dom = nextInput$2.dom; |
| 1288 |
} |
| 1289 |
} |
| 1290 |
if (nextInput$2.flags & 28 /* Component */) { |
| 1291 |
nextInput$2.parentVNode = nextVNode; |
| 1292 |
} |
| 1293 |
else if (lastInput$2.flags & 28 /* Component */) { |
| 1294 |
lastInput$2.parentVNode = nextVNode; |
| 1295 |
} |
| 1296 |
} |
| 1297 |
} |
| 1298 |
return false; |
| 1299 |
} |
| 1300 |
function patchText(lastVNode, nextVNode) { |
| 1301 |
var nextText = nextVNode.children; |
| 1302 |
var dom = lastVNode.dom; |
| 1303 |
nextVNode.dom = dom; |
| 1304 |
if (lastVNode.children !== nextText) { |
| 1305 |
dom.nodeValue = nextText; |
| 1306 |
} |
| 1307 |
} |
| 1308 |
function patchVoid(lastVNode, nextVNode) { |
| 1309 |
nextVNode.dom = lastVNode.dom; |
| 1310 |
} |
| 1311 |
function patchNonKeyedChildren(lastChildren, nextChildren, dom, lifecycle, context, isSVG, isRecycling) { |
| 1312 |
var lastChildrenLength = lastChildren.length; |
| 1313 |
var nextChildrenLength = nextChildren.length; |
| 1314 |
var commonLength = lastChildrenLength > nextChildrenLength ? nextChildrenLength : lastChildrenLength; |
| 1315 |
var i; |
| 1316 |
var nextNode = null; |
| 1317 |
var newNode; |
| 1318 |
// Loop backwards so we can use insertBefore |
| 1319 |
if (lastChildrenLength < nextChildrenLength) { |
| 1320 |
for (i = nextChildrenLength - 1; i >= commonLength; i--) { |
| 1321 |
var child = nextChildren[i]; |
| 1322 |
if (!isInvalid(child)) { |
| 1323 |
if (child.dom) { |
| 1324 |
nextChildren[i] = child = cloneVNode(child); |
| 1325 |
} |
| 1326 |
newNode = mount(child, null, lifecycle, context, isSVG); |
| 1327 |
insertOrAppend(dom, newNode, nextNode); |
| 1328 |
nextNode = newNode; |
| 1329 |
} |
| 1330 |
} |
| 1331 |
} |
| 1332 |
else if (nextChildrenLength === 0) { |
| 1333 |
removeAllChildren(dom, lastChildren, lifecycle, false, isRecycling); |
| 1334 |
} |
| 1335 |
else if (lastChildrenLength > nextChildrenLength) { |
| 1336 |
for (i = commonLength; i < lastChildrenLength; i++) { |
| 1337 |
var child$1 = lastChildren[i]; |
| 1338 |
if (!isInvalid(child$1)) { |
| 1339 |
unmount(lastChildren[i], dom, lifecycle, false, false, isRecycling); |
| 1340 |
} |
| 1341 |
} |
| 1342 |
} |
| 1343 |
for (i = commonLength - 1; i >= 0; i--) { |
| 1344 |
var lastChild = lastChildren[i]; |
| 1345 |
var nextChild = nextChildren[i]; |
| 1346 |
if (isInvalid(nextChild)) { |
| 1347 |
if (!isInvalid(lastChild)) { |
| 1348 |
unmount(lastChild, dom, lifecycle, true, false, isRecycling); |
| 1349 |
} |
| 1350 |
} |
| 1351 |
else { |
| 1352 |
if (nextChild.dom) { |
| 1353 |
nextChildren[i] = nextChild = cloneVNode(nextChild); |
| 1354 |
} |
| 1355 |
if (isInvalid(lastChild)) { |
| 1356 |
newNode = mount(nextChild, null, lifecycle, context, isSVG); |
| 1357 |
insertOrAppend(dom, newNode, nextNode); |
| 1358 |
nextNode = newNode; |
| 1359 |
} |
| 1360 |
else { |
| 1361 |
patch(lastChild, nextChild, dom, lifecycle, context, isSVG, isRecycling); |
| 1362 |
nextNode = nextChild.dom; |
| 1363 |
} |
| 1364 |
} |
| 1365 |
} |
| 1366 |
} |
| 1367 |
function patchKeyedChildren(a, b, dom, lifecycle, context, isSVG, isRecycling) { |
| 1368 |
var aLength = a.length; |
| 1369 |
var bLength = b.length; |
| 1370 |
var aEnd = aLength - 1; |
| 1371 |
var bEnd = bLength - 1; |
| 1372 |
var aStart = 0; |
| 1373 |
var bStart = 0; |
| 1374 |
var i; |
| 1375 |
var j; |
| 1376 |
var aNode; |
| 1377 |
var bNode; |
| 1378 |
var nextNode; |
| 1379 |
var nextPos; |
| 1380 |
var node; |
| 1381 |
if (aLength === 0) { |
| 1382 |
if (bLength !== 0) { |
| 1383 |
mountArrayChildren(b, dom, lifecycle, context, isSVG); |
| 1384 |
} |
| 1385 |
return; |
| 1386 |
} |
| 1387 |
else if (bLength === 0) { |
| 1388 |
removeAllChildren(dom, a, lifecycle, false, isRecycling); |
| 1389 |
return; |
| 1390 |
} |
| 1391 |
var aStartNode = a[aStart]; |
| 1392 |
var bStartNode = b[bStart]; |
| 1393 |
var aEndNode = a[aEnd]; |
| 1394 |
var bEndNode = b[bEnd]; |
| 1395 |
if (bStartNode.dom) { |
| 1396 |
b[bStart] = bStartNode = cloneVNode(bStartNode); |
| 1397 |
} |
| 1398 |
if (bEndNode.dom) { |
| 1399 |
b[bEnd] = bEndNode = cloneVNode(bEndNode); |
| 1400 |
} |
| 1401 |
// Step 1 |
| 1402 |
/* eslint no-constant-condition: 0 */ |
| 1403 |
outer: while (true) { |
| 1404 |
// Sync nodes with the same key at the beginning. |
| 1405 |
while (aStartNode.key === bStartNode.key) { |
| 1406 |
patch(aStartNode, bStartNode, dom, lifecycle, context, isSVG, isRecycling); |
| 1407 |
aStart++; |
| 1408 |
bStart++; |
| 1409 |
if (aStart > aEnd || bStart > bEnd) { |
| 1410 |
break outer; |
| 1411 |
} |
| 1412 |
aStartNode = a[aStart]; |
| 1413 |
bStartNode = b[bStart]; |
| 1414 |
if (bStartNode.dom) { |
| 1415 |
b[bStart] = bStartNode = cloneVNode(bStartNode); |
| 1416 |
} |
| 1417 |
} |
| 1418 |
// Sync nodes with the same key at the end. |
| 1419 |
while (aEndNode.key === bEndNode.key) { |
| 1420 |
patch(aEndNode, bEndNode, dom, lifecycle, context, isSVG, isRecycling); |
| 1421 |
aEnd--; |
| 1422 |
bEnd--; |
| 1423 |
if (aStart > aEnd || bStart > bEnd) { |
| 1424 |
break outer; |
| 1425 |
} |
| 1426 |
aEndNode = a[aEnd]; |
| 1427 |
bEndNode = b[bEnd]; |
| 1428 |
if (bEndNode.dom) { |
| 1429 |
b[bEnd] = bEndNode = cloneVNode(bEndNode); |
| 1430 |
} |
| 1431 |
} |
| 1432 |
// Move and sync nodes from right to left. |
| 1433 |
if (aEndNode.key === bStartNode.key) { |
| 1434 |
patch(aEndNode, bStartNode, dom, lifecycle, context, isSVG, isRecycling); |
| 1435 |
insertOrAppend(dom, bStartNode.dom, aStartNode.dom); |
| 1436 |
aEnd--; |
| 1437 |
bStart++; |
| 1438 |
aEndNode = a[aEnd]; |
| 1439 |
bStartNode = b[bStart]; |
| 1440 |
if (bStartNode.dom) { |
| 1441 |
b[bStart] = bStartNode = cloneVNode(bStartNode); |
| 1442 |
} |
| 1443 |
continue; |
| 1444 |
} |
| 1445 |
// Move and sync nodes from left to right. |
| 1446 |
if (aStartNode.key === bEndNode.key) { |
| 1447 |
patch(aStartNode, bEndNode, dom, lifecycle, context, isSVG, isRecycling); |
| 1448 |
nextPos = bEnd + 1; |
| 1449 |
nextNode = nextPos < b.length ? b[nextPos].dom : null; |
| 1450 |
insertOrAppend(dom, bEndNode.dom, nextNode); |
| 1451 |
aStart++; |
| 1452 |
bEnd--; |
| 1453 |
aStartNode = a[aStart]; |
| 1454 |
bEndNode = b[bEnd]; |
| 1455 |
if (bEndNode.dom) { |
| 1456 |
b[bEnd] = bEndNode = cloneVNode(bEndNode); |
| 1457 |
} |
| 1458 |
continue; |
| 1459 |
} |
| 1460 |
break; |
| 1461 |
} |
| 1462 |
if (aStart > aEnd) { |
| 1463 |
if (bStart <= bEnd) { |
| 1464 |
nextPos = bEnd + 1; |
| 1465 |
nextNode = nextPos < b.length ? b[nextPos].dom : null; |
| 1466 |
while (bStart <= bEnd) { |
| 1467 |
node = b[bStart]; |
| 1468 |
if (node.dom) { |
| 1469 |
b[bStart] = node = cloneVNode(node); |
| 1470 |
} |
| 1471 |
bStart++; |
| 1472 |
insertOrAppend(dom, mount(node, null, lifecycle, context, isSVG), nextNode); |
| 1473 |
} |
| 1474 |
} |
| 1475 |
} |
| 1476 |
else if (bStart > bEnd) { |
| 1477 |
while (aStart <= aEnd) { |
| 1478 |
unmount(a[aStart++], dom, lifecycle, false, false, isRecycling); |
| 1479 |
} |
| 1480 |
} |
| 1481 |
else { |
| 1482 |
aLength = aEnd - aStart + 1; |
| 1483 |
bLength = bEnd - bStart + 1; |
| 1484 |
var aNullable = a; |
| 1485 |
var sources = new Array(bLength); |
| 1486 |
// Mark all nodes as inserted. |
| 1487 |
for (i = 0; i < bLength; i++) { |
| 1488 |
sources[i] = -1; |
| 1489 |
} |
| 1490 |
var moved = false; |
| 1491 |
var pos = 0; |
| 1492 |
var patched = 0; |
| 1493 |
if ((bLength <= 4) || (aLength * bLength <= 16)) { |
| 1494 |
for (i = aStart; i <= aEnd; i++) { |
| 1495 |
aNode = a[i]; |
| 1496 |
if (patched < bLength) { |
| 1497 |
for (j = bStart; j <= bEnd; j++) { |
| 1498 |
bNode = b[j]; |
| 1499 |
if (aNode.key === bNode.key) { |
| 1500 |
sources[j - bStart] = i; |
| 1501 |
if (pos > j) { |
| 1502 |
moved = true; |
| 1503 |
} |
| 1504 |
else { |
| 1505 |
pos = j; |
| 1506 |
} |
| 1507 |
if (bNode.dom) { |
| 1508 |
b[j] = bNode = cloneVNode(bNode); |
| 1509 |
} |
| 1510 |
patch(aNode, bNode, dom, lifecycle, context, isSVG, isRecycling); |
| 1511 |
patched++; |
| 1512 |
aNullable[i] = null; |
| 1513 |
break; |
| 1514 |
} |
| 1515 |
} |
| 1516 |
} |
| 1517 |
} |
| 1518 |
} |
| 1519 |
else { |
| 1520 |
var keyIndex = new Map(); |
| 1521 |
for (i = bStart; i <= bEnd; i++) { |
| 1522 |
node = b[i]; |
| 1523 |
keyIndex.set(node.key, i); |
| 1524 |
} |
| 1525 |
for (i = aStart; i <= aEnd; i++) { |
| 1526 |
aNode = a[i]; |
| 1527 |
if (patched < bLength) { |
| 1528 |
j = keyIndex.get(aNode.key); |
| 1529 |
if (!isUndefined(j)) { |
| 1530 |
bNode = b[j]; |
| 1531 |
sources[j - bStart] = i; |
| 1532 |
if (pos > j) { |
| 1533 |
moved = true; |
| 1534 |
} |
| 1535 |
else { |
| 1536 |
pos = j; |
| 1537 |
} |
| 1538 |
if (bNode.dom) { |
| 1539 |
b[j] = bNode = cloneVNode(bNode); |
| 1540 |
} |
| 1541 |
patch(aNode, bNode, dom, lifecycle, context, isSVG, isRecycling); |
| 1542 |
patched++; |
| 1543 |
aNullable[i] = null; |
| 1544 |
} |
| 1545 |
} |
| 1546 |
} |
| 1547 |
} |
| 1548 |
if (aLength === a.length && patched === 0) { |
| 1549 |
removeAllChildren(dom, a, lifecycle, false, isRecycling); |
| 1550 |
while (bStart < bLength) { |
| 1551 |
node = b[bStart]; |
| 1552 |
if (node.dom) { |
| 1553 |
b[bStart] = node = cloneVNode(node); |
| 1554 |
} |
| 1555 |
bStart++; |
| 1556 |
insertOrAppend(dom, mount(node, null, lifecycle, context, isSVG), null); |
| 1557 |
} |
| 1558 |
} |
| 1559 |
else { |
| 1560 |
i = aLength - patched; |
| 1561 |
while (i > 0) { |
| 1562 |
aNode = aNullable[aStart++]; |
| 1563 |
if (!isNull(aNode)) { |
| 1564 |
unmount(aNode, dom, lifecycle, false, false, isRecycling); |
| 1565 |
i--; |
| 1566 |
} |
| 1567 |
} |
| 1568 |
if (moved) { |
| 1569 |
var seq = lis_algorithm(sources); |
| 1570 |
j = seq.length - 1; |
| 1571 |
for (i = bLength - 1; i >= 0; i--) { |
| 1572 |
if (sources[i] === -1) { |
| 1573 |
pos = i + bStart; |
| 1574 |
node = b[pos]; |
| 1575 |
if (node.dom) { |
| 1576 |
b[pos] = node = cloneVNode(node); |
| 1577 |
} |
| 1578 |
nextPos = pos + 1; |
| 1579 |
nextNode = nextPos < b.length ? b[nextPos].dom : null; |
| 1580 |
insertOrAppend(dom, mount(node, dom, lifecycle, context, isSVG), nextNode); |
| 1581 |
} |
| 1582 |
else { |
| 1583 |
if (j < 0 || i !== seq[j]) { |
| 1584 |
pos = i + bStart; |
| 1585 |
node = b[pos]; |
| 1586 |
nextPos = pos + 1; |
| 1587 |
nextNode = nextPos < b.length ? b[nextPos].dom : null; |
| 1588 |
insertOrAppend(dom, node.dom, nextNode); |
| 1589 |
} |
| 1590 |
else { |
| 1591 |
j--; |
| 1592 |
} |
| 1593 |
} |
| 1594 |
} |
| 1595 |
} |
| 1596 |
else if (patched !== bLength) { |
| 1597 |
for (i = bLength - 1; i >= 0; i--) { |
| 1598 |
if (sources[i] === -1) { |
| 1599 |
pos = i + bStart; |
| 1600 |
node = b[pos]; |
| 1601 |
if (node.dom) { |
| 1602 |
b[pos] = node = cloneVNode(node); |
| 1603 |
} |
| 1604 |
nextPos = pos + 1; |
| 1605 |
nextNode = nextPos < b.length ? b[nextPos].dom : null; |
| 1606 |
insertOrAppend(dom, mount(node, null, lifecycle, context, isSVG), nextNode); |
| 1607 |
} |
| 1608 |
} |
| 1609 |
} |
| 1610 |
} |
| 1611 |
} |
| 1612 |
} |
| 1613 |
// // https://en.wikipedia.org/wiki/Longest_increasing_subsequence |
| 1614 |
function lis_algorithm(a) { |
| 1615 |
var p = a.slice(0); |
| 1616 |
var result = []; |
| 1617 |
result.push(0); |
| 1618 |
var i; |
| 1619 |
var j; |
| 1620 |
var u; |
| 1621 |
var v; |
| 1622 |
var c; |
| 1623 |
for (i = 0; i < a.length; i++) { |
| 1624 |
if (a[i] === -1) { |
| 1625 |
continue; |
| 1626 |
} |
| 1627 |
j = result[result.length - 1]; |
| 1628 |
if (a[j] < a[i]) { |
| 1629 |
p[i] = j; |
| 1630 |
result.push(i); |
| 1631 |
continue; |
| 1632 |
} |
| 1633 |
u = 0; |
| 1634 |
v = result.length - 1; |
| 1635 |
while (u < v) { |
| 1636 |
c = ((u + v) / 2) | 0; |
| 1637 |
if (a[result[c]] < a[i]) { |
| 1638 |
u = c + 1; |
| 1639 |
} |
| 1640 |
else { |
| 1641 |
v = c; |
| 1642 |
} |
| 1643 |
} |
| 1644 |
if (a[i] < a[result[u]]) { |
| 1645 |
if (u > 0) { |
| 1646 |
p[i] = result[u - 1]; |
| 1647 |
} |
| 1648 |
result[u] = i; |
| 1649 |
} |
| 1650 |
} |
| 1651 |
u = result.length; |
| 1652 |
v = result[u - 1]; |
| 1653 |
while (u-- > 0) { |
| 1654 |
result[u] = v; |
| 1655 |
v = p[v]; |
| 1656 |
} |
| 1657 |
return result; |
| 1658 |
} |
| 1659 |
function patchProp(prop, lastValue, nextValue, dom, isSVG, lifecycle) { |
| 1660 |
if (skipProps[prop]) { |
| 1661 |
return; |
| 1662 |
} |
| 1663 |
if (booleanProps[prop]) { |
| 1664 |
dom[prop] = nextValue ? true : false; |
| 1665 |
} |
| 1666 |
else if (strictProps[prop]) { |
| 1667 |
var value = isNullOrUndef(nextValue) ? '' : nextValue; |
| 1668 |
if (dom[prop] !== value) { |
| 1669 |
dom[prop] = value; |
| 1670 |
} |
| 1671 |
} |
| 1672 |
else if (isAttrAnEvent(prop)) { |
| 1673 |
patchEvent(prop, lastValue, nextValue, dom, lifecycle); |
| 1674 |
} |
| 1675 |
else if (lastValue !== nextValue) { |
| 1676 |
if (isNullOrUndef(nextValue)) { |
| 1677 |
dom.removeAttribute(prop); |
| 1678 |
} |
| 1679 |
else if (prop === 'className') { |
| 1680 |
if (isSVG) { |
| 1681 |
dom.setAttribute('class', nextValue); |
| 1682 |
} |
| 1683 |
else { |
| 1684 |
dom.className = nextValue; |
| 1685 |
} |
| 1686 |
} |
| 1687 |
else if (prop === 'style') { |
| 1688 |
patchStyle(lastValue, nextValue, dom); |
| 1689 |
} |
| 1690 |
else if (prop === 'dangerouslySetInnerHTML') { |
| 1691 |
var lastHtml = lastValue && lastValue.__html; |
| 1692 |
var nextHtml = nextValue && nextValue.__html; |
| 1693 |
if (lastHtml !== nextHtml) { |
| 1694 |
if (!isNullOrUndef(nextHtml)) { |
| 1695 |
dom.innerHTML = nextHtml; |
| 1696 |
} |
| 1697 |
} |
| 1698 |
} |
| 1699 |
else if (prop !== 'childrenType' && prop !== 'ref' && prop !== 'key') { |
| 1700 |
var dehyphenProp = dehyphenProps[prop]; |
| 1701 |
var ns = namespaces[prop]; |
| 1702 |
if (ns) { |
| 1703 |
dom.setAttributeNS(ns, dehyphenProp || prop, nextValue); |
| 1704 |
} |
| 1705 |
else { |
| 1706 |
dom.setAttribute(dehyphenProp || prop, nextValue); |
| 1707 |
} |
| 1708 |
} |
| 1709 |
} |
| 1710 |
} |
| 1711 |
function patchEvents(lastEvents, nextEvents, dom, lifecycle) { |
| 1712 |
lastEvents = lastEvents || EMPTY_OBJ; |
| 1713 |
nextEvents = nextEvents || EMPTY_OBJ; |
| 1714 |
if (nextEvents !== EMPTY_OBJ) { |
| 1715 |
for (var name in nextEvents) { |
| 1716 |
// do not add a hasOwnProperty check here, it affects performance |
| 1717 |
patchEvent(name, lastEvents[name], nextEvents[name], dom, lifecycle); |
| 1718 |
} |
| 1719 |
} |
| 1720 |
if (lastEvents !== EMPTY_OBJ) { |
| 1721 |
for (var name$1 in lastEvents) { |
| 1722 |
// do not add a hasOwnProperty check here, it affects performance |
| 1723 |
if (isNullOrUndef(nextEvents[name$1])) { |
| 1724 |
patchEvent(name$1, lastEvents[name$1], null, dom, lifecycle); |
| 1725 |
} |
| 1726 |
} |
| 1727 |
} |
| 1728 |
} |
| 1729 |
function patchEvent(name, lastValue, nextValue, dom, lifecycle) { |
| 1730 |
if (lastValue !== nextValue) { |
| 1731 |
var nameLowerCase = name.toLowerCase(); |
| 1732 |
var domEvent = dom[nameLowerCase]; |
| 1733 |
// if the function is wrapped, that means it's been controlled by a wrapper |
| 1734 |
if (domEvent && domEvent.wrapped) { |
| 1735 |
return; |
| 1736 |
} |
| 1737 |
if (delegatedProps[name]) { |
| 1738 |
lifecycle.fastUnmount = false; |
| 1739 |
handleEvent(name, lastValue, nextValue, dom); |
| 1740 |
} |
| 1741 |
else { |
| 1742 |
dom[nameLowerCase] = nextValue; |
| 1743 |
} |
| 1744 |
} |
| 1745 |
} |
| 1746 |
function patchProps(lastProps, nextProps, dom, lifecycle, context, isSVG) { |
| 1747 |
lastProps = lastProps || EMPTY_OBJ; |
| 1748 |
nextProps = nextProps || EMPTY_OBJ; |
| 1749 |
if (nextProps !== EMPTY_OBJ) { |
| 1750 |
for (var prop in nextProps) { |
| 1751 |
// do not add a hasOwnProperty check here, it affects performance |
| 1752 |
var nextValue = nextProps[prop]; |
| 1753 |
var lastValue = lastProps[prop]; |
| 1754 |
if (isNullOrUndef(nextValue)) { |
| 1755 |
removeProp(prop, dom); |
| 1756 |
} |
| 1757 |
else { |
| 1758 |
patchProp(prop, lastValue, nextValue, dom, isSVG, lifecycle); |
| 1759 |
} |
| 1760 |
} |
| 1761 |
} |
| 1762 |
if (lastProps !== EMPTY_OBJ) { |
| 1763 |
for (var prop$1 in lastProps) { |
| 1764 |
// do not add a hasOwnProperty check here, it affects performance |
| 1765 |
if (isNullOrUndef(nextProps[prop$1])) { |
| 1766 |
removeProp(prop$1, dom); |
| 1767 |
} |
| 1768 |
} |
| 1769 |
} |
| 1770 |
} |
| 1771 |
// We are assuming here that we come from patchProp routine |
| 1772 |
// -nextAttrValue cannot be null or undefined |
| 1773 |
function patchStyle(lastAttrValue, nextAttrValue, dom) { |
| 1774 |
if (isString(nextAttrValue)) { |
| 1775 |
dom.style.cssText = nextAttrValue; |
| 1776 |
return; |
| 1777 |
} |
| 1778 |
for (var style in nextAttrValue) { |
| 1779 |
// do not add a hasOwnProperty check here, it affects performance |
| 1780 |
var value = nextAttrValue[style]; |
| 1781 |
if (isNumber(value) && !isUnitlessNumber[style]) { |
| 1782 |
dom.style[style] = value + 'px'; |
| 1783 |
} |
| 1784 |
else { |
| 1785 |
dom.style[style] = value; |
| 1786 |
} |
| 1787 |
} |
| 1788 |
if (!isNullOrUndef(lastAttrValue)) { |
| 1789 |
for (var style$1 in lastAttrValue) { |
| 1790 |
if (isNullOrUndef(nextAttrValue[style$1])) { |
| 1791 |
dom.style[style$1] = ''; |
| 1792 |
} |
| 1793 |
} |
| 1794 |
} |
| 1795 |
} |
| 1796 |
function removeProp(prop, dom) { |
| 1797 |
if (prop === 'className') { |
| 1798 |
dom.removeAttribute('class'); |
| 1799 |
} |
| 1800 |
else if (prop === 'value') { |
| 1801 |
dom.value = ''; |
| 1802 |
} |
| 1803 |
else if (prop === 'style') { |
| 1804 |
dom.style.cssText = null; |
| 1805 |
dom.removeAttribute('style'); |
| 1806 |
} |
| 1807 |
else if (delegatedProps[prop]) { |
| 1808 |
handleEvent(prop, null, null, dom); |
| 1809 |
} |
| 1810 |
else { |
| 1811 |
dom.removeAttribute(prop); |
| 1812 |
} |
| 1813 |
} |
| 1814 |
|
| 1815 |
var recyclingEnabled = true; |
| 1816 |
var componentPools = new Map(); |
| 1817 |
var elementPools = new Map(); |
| 1818 |
function disableRecycling() { |
| 1819 |
recyclingEnabled = false; |
| 1820 |
componentPools.clear(); |
| 1821 |
elementPools.clear(); |
| 1822 |
} |
| 1823 |
|
| 1824 |
function recycleElement(vNode, lifecycle, context, isSVG) { |
| 1825 |
var tag = vNode.type; |
| 1826 |
var key = vNode.key; |
| 1827 |
var pools = elementPools.get(tag); |
| 1828 |
if (!isUndefined(pools)) { |
| 1829 |
var pool = key === null ? pools.nonKeyed : pools.keyed.get(key); |
| 1830 |
if (!isUndefined(pool)) { |
| 1831 |
var recycledVNode = pool.pop(); |
| 1832 |
if (!isUndefined(recycledVNode)) { |
| 1833 |
patchElement(recycledVNode, vNode, null, lifecycle, context, isSVG, true); |
| 1834 |
return vNode.dom; |
| 1835 |
} |
| 1836 |
} |
| 1837 |
} |
| 1838 |
return null; |
| 1839 |
} |
| 1840 |
function poolElement(vNode) { |
| 1841 |
var tag = vNode.type; |
| 1842 |
var key = vNode.key; |
| 1843 |
var pools = elementPools.get(tag); |
| 1844 |
if (isUndefined(pools)) { |
| 1845 |
pools = { |
| 1846 |
nonKeyed: [], |
| 1847 |
keyed: new Map() |
| 1848 |
}; |
| 1849 |
elementPools.set(tag, pools); |
| 1850 |
} |
| 1851 |
if (isNull(key)) { |
| 1852 |
pools.nonKeyed.push(vNode); |
| 1853 |
} |
| 1854 |
else { |
| 1855 |
var pool = pools.keyed.get(key); |
| 1856 |
if (isUndefined(pool)) { |
| 1857 |
pool = []; |
| 1858 |
pools.keyed.set(key, pool); |
| 1859 |
} |
| 1860 |
pool.push(vNode); |
| 1861 |
} |
| 1862 |
} |
| 1863 |
function recycleComponent(vNode, lifecycle, context, isSVG) { |
| 1864 |
var type = vNode.type; |
| 1865 |
var key = vNode.key; |
| 1866 |
var pools = componentPools.get(type); |
| 1867 |
if (!isUndefined(pools)) { |
| 1868 |
var pool = key === null ? pools.nonKeyed : pools.keyed.get(key); |
| 1869 |
if (!isUndefined(pool)) { |
| 1870 |
var recycledVNode = pool.pop(); |
| 1871 |
if (!isUndefined(recycledVNode)) { |
| 1872 |
var flags = vNode.flags; |
| 1873 |
var failed = patchComponent(recycledVNode, vNode, null, lifecycle, context, isSVG, flags & 4 /* ComponentClass */, true); |
| 1874 |
if (!failed) { |
| 1875 |
return vNode.dom; |
| 1876 |
} |
| 1877 |
} |
| 1878 |
} |
| 1879 |
} |
| 1880 |
return null; |
| 1881 |
} |
| 1882 |
function poolComponent(vNode) { |
| 1883 |
var type = vNode.type; |
| 1884 |
var key = vNode.key; |
| 1885 |
var hooks = vNode.ref; |
| 1886 |
var nonRecycleHooks = hooks && (hooks.onComponentWillMount || |
| 1887 |
hooks.onComponentWillUnmount || |
| 1888 |
hooks.onComponentDidMount || |
| 1889 |
hooks.onComponentWillUpdate || |
| 1890 |
hooks.onComponentDidUpdate); |
| 1891 |
if (nonRecycleHooks) { |
| 1892 |
return; |
| 1893 |
} |
| 1894 |
var pools = componentPools.get(type); |
| 1895 |
if (isUndefined(pools)) { |
| 1896 |
pools = { |
| 1897 |
nonKeyed: [], |
| 1898 |
keyed: new Map() |
| 1899 |
}; |
| 1900 |
componentPools.set(type, pools); |
| 1901 |
} |
| 1902 |
if (isNull(key)) { |
| 1903 |
pools.nonKeyed.push(vNode); |
| 1904 |
} |
| 1905 |
else { |
| 1906 |
var pool = pools.keyed.get(key); |
| 1907 |
if (isUndefined(pool)) { |
| 1908 |
pool = []; |
| 1909 |
pools.keyed.set(key, pool); |
| 1910 |
} |
| 1911 |
pool.push(vNode); |
| 1912 |
} |
| 1913 |
} |
| 1914 |
|
| 1915 |
function mount(vNode, parentDom, lifecycle, context, isSVG) { |
| 1916 |
var flags = vNode.flags; |
| 1917 |
if (flags & 3970 /* Element */) { |
| 1918 |
return mountElement(vNode, parentDom, lifecycle, context, isSVG); |
| 1919 |
} |
| 1920 |
else if (flags & 28 /* Component */) { |
| 1921 |
return mountComponent(vNode, parentDom, lifecycle, context, isSVG, flags & 4 /* ComponentClass */); |
| 1922 |
} |
| 1923 |
else if (flags & 4096 /* Void */) { |
| 1924 |
return mountVoid(vNode, parentDom); |
| 1925 |
} |
| 1926 |
else if (flags & 1 /* Text */) { |
| 1927 |
return mountText(vNode, parentDom); |
| 1928 |
} |
| 1929 |
else { |
| 1930 |
if (false) { |
| 1931 |
throwError(("mount() expects a valid VNode, instead it received an object with the type \"" + (typeof vNode) + "\".")); |
| 1932 |
} |
| 1933 |
throwError(); |
| 1934 |
} |
| 1935 |
} |
| 1936 |
function mountText(vNode, parentDom) { |
| 1937 |
var dom = document.createTextNode(vNode.children); |
| 1938 |
vNode.dom = dom; |
| 1939 |
if (parentDom) { |
| 1940 |
appendChild(parentDom, dom); |
| 1941 |
} |
| 1942 |
return dom; |
| 1943 |
} |
| 1944 |
function mountVoid(vNode, parentDom) { |
| 1945 |
var dom = document.createTextNode(''); |
| 1946 |
vNode.dom = dom; |
| 1947 |
if (parentDom) { |
| 1948 |
appendChild(parentDom, dom); |
| 1949 |
} |
| 1950 |
return dom; |
| 1951 |
} |
| 1952 |
function mountElement(vNode, parentDom, lifecycle, context, isSVG) { |
| 1953 |
if (recyclingEnabled) { |
| 1954 |
var dom$1 = recycleElement(vNode, lifecycle, context, isSVG); |
| 1955 |
if (!isNull(dom$1)) { |
| 1956 |
if (!isNull(parentDom)) { |
| 1957 |
appendChild(parentDom, dom$1); |
| 1958 |
} |
| 1959 |
return dom$1; |
| 1960 |
} |
| 1961 |
} |
| 1962 |
var tag = vNode.type; |
| 1963 |
var flags = vNode.flags; |
| 1964 |
if (isSVG || (flags & 128 /* SvgElement */)) { |
| 1965 |
isSVG = true; |
| 1966 |
} |
| 1967 |
var dom = documentCreateElement(tag, isSVG); |
| 1968 |
var children = vNode.children; |
| 1969 |
var props = vNode.props; |
| 1970 |
var events = vNode.events; |
| 1971 |
var ref = vNode.ref; |
| 1972 |
vNode.dom = dom; |
| 1973 |
if (!isNull(children)) { |
| 1974 |
if (isStringOrNumber(children)) { |
| 1975 |
setTextContent(dom, children); |
| 1976 |
} |
| 1977 |
else if (isArray(children)) { |
| 1978 |
mountArrayChildren(children, dom, lifecycle, context, isSVG); |
| 1979 |
} |
| 1980 |
else if (isVNode(children)) { |
| 1981 |
mount(children, dom, lifecycle, context, isSVG); |
| 1982 |
} |
| 1983 |
} |
| 1984 |
if (!(flags & 2 /* HtmlElement */)) { |
| 1985 |
processElement(flags, vNode, dom); |
| 1986 |
} |
| 1987 |
if (!isNull(props)) { |
| 1988 |
for (var prop in props) { |
| 1989 |
// do not add a hasOwnProperty check here, it affects performance |
| 1990 |
patchProp(prop, null, props[prop], dom, isSVG, lifecycle); |
| 1991 |
} |
| 1992 |
} |
| 1993 |
if (!isNull(events)) { |
| 1994 |
for (var name in events) { |
| 1995 |
// do not add a hasOwnProperty check here, it affects performance |
| 1996 |
patchEvent(name, null, events[name], dom, lifecycle); |
| 1997 |
} |
| 1998 |
} |
| 1999 |
if (!isNull(ref)) { |
| 2000 |
mountRef(dom, ref, lifecycle); |
| 2001 |
} |
| 2002 |
if (!isNull(parentDom)) { |
| 2003 |
appendChild(parentDom, dom); |
| 2004 |
} |
| 2005 |
return dom; |
| 2006 |
} |
| 2007 |
function mountArrayChildren(children, dom, lifecycle, context, isSVG) { |
| 2008 |
for (var i = 0; i < children.length; i++) { |
| 2009 |
var child = children[i]; |
| 2010 |
if (!isInvalid(child)) { |
| 2011 |
if (child.dom) { |
| 2012 |
children[i] = child = cloneVNode(child); |
| 2013 |
} |
| 2014 |
mount(children[i], dom, lifecycle, context, isSVG); |
| 2015 |
} |
| 2016 |
} |
| 2017 |
} |
| 2018 |
function mountComponent(vNode, parentDom, lifecycle, context, isSVG, isClass) { |
| 2019 |
if (recyclingEnabled) { |
| 2020 |
var dom$1 = recycleComponent(vNode, lifecycle, context, isSVG); |
| 2021 |
if (!isNull(dom$1)) { |
| 2022 |
if (!isNull(parentDom)) { |
| 2023 |
appendChild(parentDom, dom$1); |
| 2024 |
} |
| 2025 |
return dom$1; |
| 2026 |
} |
| 2027 |
} |
| 2028 |
var type = vNode.type; |
| 2029 |
var props = vNode.props || EMPTY_OBJ; |
| 2030 |
var ref = vNode.ref; |
| 2031 |
var dom; |
| 2032 |
if (isClass) { |
| 2033 |
var defaultProps = type.defaultProps; |
| 2034 |
lifecycle.fastUnmount = false; |
| 2035 |
if (!isUndefined(defaultProps)) { |
| 2036 |
copyPropsTo(defaultProps, props); |
| 2037 |
vNode.props = props; |
| 2038 |
} |
| 2039 |
var instance = createStatefulComponentInstance(vNode, type, props, context, isSVG, devToolsStatus); |
| 2040 |
var input = instance._lastInput; |
| 2041 |
var fastUnmount = lifecycle.fastUnmount; |
| 2042 |
// we store the fastUnmount value, but we set it back to true on the lifecycle |
| 2043 |
// we do this so we can determine if the component render has a fastUnmount or not |
| 2044 |
lifecycle.fastUnmount = true; |
| 2045 |
instance._vNode = vNode; |
| 2046 |
vNode.dom = dom = mount(input, null, lifecycle, instance._childContext, isSVG); |
| 2047 |
// we now create a lifecycle for this component and store the fastUnmount value |
| 2048 |
var subLifecycle = instance._lifecycle = new Lifecycle(); |
| 2049 |
subLifecycle.fastUnmount = lifecycle.fastUnmount; |
| 2050 |
// we then set the lifecycle fastUnmount value back to what it was before the mount |
| 2051 |
lifecycle.fastUnmount = fastUnmount; |
| 2052 |
if (!isNull(parentDom)) { |
| 2053 |
appendChild(parentDom, dom); |
| 2054 |
} |
| 2055 |
mountStatefulComponentCallbacks(ref, instance, lifecycle); |
| 2056 |
findDOMNodeEnabled && componentToDOMNodeMap.set(instance, dom); |
| 2057 |
vNode.children = instance; |
| 2058 |
} |
| 2059 |
else { |
| 2060 |
var input$1 = createStatelessComponentInput(vNode, type, props, context); |
| 2061 |
vNode.dom = dom = mount(input$1, null, lifecycle, context, isSVG); |
| 2062 |
vNode.children = input$1; |
| 2063 |
mountStatelessComponentCallbacks(ref, dom, lifecycle); |
| 2064 |
if (!isNull(parentDom)) { |
| 2065 |
appendChild(parentDom, dom); |
| 2066 |
} |
| 2067 |
} |
| 2068 |
return dom; |
| 2069 |
} |
| 2070 |
function mountStatefulComponentCallbacks(ref, instance, lifecycle) { |
| 2071 |
if (ref) { |
| 2072 |
if (isFunction(ref)) { |
| 2073 |
ref(instance); |
| 2074 |
} |
| 2075 |
else { |
| 2076 |
if (false) { |
| 2077 |
throwError('string "refs" are not supported in Inferno 1.0. Use callback "refs" instead.'); |
| 2078 |
} |
| 2079 |
throwError(); |
| 2080 |
} |
| 2081 |
} |
| 2082 |
if (!isNull(instance.componentDidMount)) { |
| 2083 |
lifecycle.addListener(function () { |
| 2084 |
instance.componentDidMount(); |
| 2085 |
}); |
| 2086 |
} |
| 2087 |
} |
| 2088 |
function mountStatelessComponentCallbacks(ref, dom, lifecycle) { |
| 2089 |
if (ref) { |
| 2090 |
if (!isNullOrUndef(ref.onComponentWillMount)) { |
| 2091 |
lifecycle.fastUnmount = false; |
| 2092 |
ref.onComponentWillMount(); |
| 2093 |
} |
| 2094 |
if (!isNullOrUndef(ref.onComponentDidMount)) { |
| 2095 |
lifecycle.fastUnmount = false; |
| 2096 |
lifecycle.addListener(function () { return ref.onComponentDidMount(dom); }); |
| 2097 |
} |
| 2098 |
} |
| 2099 |
} |
| 2100 |
function mountRef(dom, value, lifecycle) { |
| 2101 |
if (isFunction(value)) { |
| 2102 |
lifecycle.fastUnmount = false; |
| 2103 |
lifecycle.addListener(function () { return value(dom); }); |
| 2104 |
} |
| 2105 |
else { |
| 2106 |
if (isInvalid(value)) { |
| 2107 |
return; |
| 2108 |
} |
| 2109 |
if (false) { |
| 2110 |
throwError('string "refs" are not supported in Inferno 1.0. Use callback "refs" instead.'); |
| 2111 |
} |
| 2112 |
throwError(); |
| 2113 |
} |
| 2114 |
} |
| 2115 |
|
| 2116 |
function copyPropsTo(copyFrom, copyTo) { |
| 2117 |
for (var prop in copyFrom) { |
| 2118 |
if (isUndefined(copyTo[prop])) { |
| 2119 |
copyTo[prop] = copyFrom[prop]; |
| 2120 |
} |
| 2121 |
} |
| 2122 |
} |
| 2123 |
function createStatefulComponentInstance(vNode, Component, props, context, isSVG, devToolsStatus) { |
| 2124 |
if (isUndefined(context)) { |
| 2125 |
context = {}; |
| 2126 |
} |
| 2127 |
var instance = new Component(props, context); |
| 2128 |
instance.context = context; |
| 2129 |
if (instance.props === EMPTY_OBJ) { |
| 2130 |
instance.props = props; |
| 2131 |
} |
| 2132 |
instance._patch = patch; |
| 2133 |
instance._devToolsStatus = devToolsStatus; |
| 2134 |
if (findDOMNodeEnabled) { |
| 2135 |
instance._componentToDOMNodeMap = componentToDOMNodeMap; |
| 2136 |
} |
| 2137 |
var childContext = instance.getChildContext(); |
| 2138 |
if (!isNullOrUndef(childContext)) { |
| 2139 |
instance._childContext = Object.assign({}, context, childContext); |
| 2140 |
} |
| 2141 |
else { |
| 2142 |
instance._childContext = context; |
| 2143 |
} |
| 2144 |
instance._unmounted = false; |
| 2145 |
instance._pendingSetState = true; |
| 2146 |
instance._isSVG = isSVG; |
| 2147 |
instance.componentWillMount(); |
| 2148 |
instance._beforeRender && instance._beforeRender(); |
| 2149 |
var input = instance.render(props, instance.state, context); |
| 2150 |
instance._afterRender && instance._afterRender(); |
| 2151 |
if (isArray(input)) { |
| 2152 |
if (false) { |
| 2153 |
throwError('a valid Inferno VNode (or null) must be returned from a component render. You may have returned an array or an invalid object.'); |
| 2154 |
} |
| 2155 |
throwError(); |
| 2156 |
} |
| 2157 |
else if (isInvalid(input)) { |
| 2158 |
input = createVoidVNode(); |
| 2159 |
} |
| 2160 |
else { |
| 2161 |
if (input.dom) { |
| 2162 |
input = cloneVNode(input); |
| 2163 |
} |
| 2164 |
if (input.flags & 28 /* Component */) { |
| 2165 |
// if we have an input that is also a component, we run into a tricky situation |
| 2166 |
// where the root vNode needs to always have the correct DOM entry |
| 2167 |
// so we break monomorphism on our input and supply it our vNode as parentVNode |
| 2168 |
// we can optimise this in the future, but this gets us out of a lot of issues |
| 2169 |
input.parentVNode = vNode; |
| 2170 |
} |
| 2171 |
} |
| 2172 |
instance._pendingSetState = false; |
| 2173 |
instance._lastInput = input; |
| 2174 |
return instance; |
| 2175 |
} |
| 2176 |
function replaceLastChildAndUnmount(lastInput, nextInput, parentDom, lifecycle, context, isSVG, isRecycling) { |
| 2177 |
replaceVNode(parentDom, mount(nextInput, null, lifecycle, context, isSVG), lastInput, lifecycle, isRecycling); |
| 2178 |
} |
| 2179 |
function replaceVNode(parentDom, dom, vNode, lifecycle, isRecycling) { |
| 2180 |
var shallowUnmount = false; |
| 2181 |
// we cannot cache nodeType here as vNode might be re-assigned below |
| 2182 |
if (vNode.flags & 28 /* Component */) { |
| 2183 |
// if we are accessing a stateful or stateless component, we want to access their last rendered input |
| 2184 |
// accessing their DOM node is not useful to us here |
| 2185 |
unmount(vNode, null, lifecycle, false, false, isRecycling); |
| 2186 |
vNode = vNode.children._lastInput || vNode.children; |
| 2187 |
shallowUnmount = true; |
| 2188 |
} |
| 2189 |
replaceChild(parentDom, dom, vNode.dom); |
| 2190 |
unmount(vNode, null, lifecycle, false, shallowUnmount, isRecycling); |
| 2191 |
} |
| 2192 |
function createStatelessComponentInput(vNode, component, props, context) { |
| 2193 |
var input = component(props, context); |
| 2194 |
if (isArray(input)) { |
| 2195 |
if (false) { |
| 2196 |
throwError('a valid Inferno VNode (or null) must be returned from a component render. You may have returned an array or an invalid object.'); |
| 2197 |
} |
| 2198 |
throwError(); |
| 2199 |
} |
| 2200 |
else if (isInvalid(input)) { |
| 2201 |
input = createVoidVNode(); |
| 2202 |
} |
| 2203 |
else { |
| 2204 |
if (input.dom) { |
| 2205 |
input = cloneVNode(input); |
| 2206 |
} |
| 2207 |
if (input.flags & 28 /* Component */) { |
| 2208 |
// if we have an input that is also a component, we run into a tricky situation |
| 2209 |
// where the root vNode needs to always have the correct DOM entry |
| 2210 |
// so we break monomorphism on our input and supply it our vNode as parentVNode |
| 2211 |
// we can optimise this in the future, but this gets us out of a lot of issues |
| 2212 |
input.parentVNode = vNode; |
| 2213 |
} |
| 2214 |
} |
| 2215 |
return input; |
| 2216 |
} |
| 2217 |
function setTextContent(dom, text) { |
| 2218 |
if (text !== '') { |
| 2219 |
dom.textContent = text; |
| 2220 |
} |
| 2221 |
else { |
| 2222 |
dom.appendChild(document.createTextNode('')); |
| 2223 |
} |
| 2224 |
} |
| 2225 |
function updateTextContent(dom, text) { |
| 2226 |
dom.firstChild.nodeValue = text; |
| 2227 |
} |
| 2228 |
function appendChild(parentDom, dom) { |
| 2229 |
parentDom.appendChild(dom); |
| 2230 |
} |
| 2231 |
function insertOrAppend(parentDom, newNode, nextNode) { |
| 2232 |
if (isNullOrUndef(nextNode)) { |
| 2233 |
appendChild(parentDom, newNode); |
| 2234 |
} |
| 2235 |
else { |
| 2236 |
parentDom.insertBefore(newNode, nextNode); |
| 2237 |
} |
| 2238 |
} |
| 2239 |
function documentCreateElement(tag, isSVG) { |
| 2240 |
if (isSVG === true) { |
| 2241 |
return document.createElementNS(svgNS, tag); |
| 2242 |
} |
| 2243 |
else { |
| 2244 |
return document.createElement(tag); |
| 2245 |
} |
| 2246 |
} |
| 2247 |
function replaceWithNewNode(lastNode, nextNode, parentDom, lifecycle, context, isSVG, isRecycling) { |
| 2248 |
unmount(lastNode, null, lifecycle, false, false, isRecycling); |
| 2249 |
var dom = mount(nextNode, null, lifecycle, context, isSVG); |
| 2250 |
nextNode.dom = dom; |
| 2251 |
replaceChild(parentDom, dom, lastNode.dom); |
| 2252 |
} |
| 2253 |
function replaceChild(parentDom, nextDom, lastDom) { |
| 2254 |
if (!parentDom) { |
| 2255 |
parentDom = lastDom.parentNode; |
| 2256 |
} |
| 2257 |
parentDom.replaceChild(nextDom, lastDom); |
| 2258 |
} |
| 2259 |
function removeChild(parentDom, dom) { |
| 2260 |
parentDom.removeChild(dom); |
| 2261 |
} |
| 2262 |
function removeAllChildren(dom, children, lifecycle, shallowUnmount, isRecycling) { |
| 2263 |
dom.textContent = ''; |
| 2264 |
if (!lifecycle.fastUnmount) { |
| 2265 |
removeChildren(null, children, lifecycle, shallowUnmount, isRecycling); |
| 2266 |
} |
| 2267 |
} |
| 2268 |
function removeChildren(dom, children, lifecycle, shallowUnmount, isRecycling) { |
| 2269 |
for (var i = 0; i < children.length; i++) { |
| 2270 |
var child = children[i]; |
| 2271 |
if (!isInvalid(child)) { |
| 2272 |
unmount(child, dom, lifecycle, true, shallowUnmount, isRecycling); |
| 2273 |
} |
| 2274 |
} |
| 2275 |
} |
| 2276 |
function isKeyed(lastChildren, nextChildren) { |
| 2277 |
return nextChildren.length && !isNullOrUndef(nextChildren[0]) && !isNullOrUndef(nextChildren[0].key) |
| 2278 |
&& lastChildren.length && !isNullOrUndef(lastChildren[0]) && !isNullOrUndef(lastChildren[0].key); |
| 2279 |
} |
| 2280 |
|
| 2281 |
function normaliseChildNodes(dom) { |
| 2282 |
var rawChildNodes = dom.childNodes; |
| 2283 |
var length = rawChildNodes.length; |
| 2284 |
var i = 0; |
| 2285 |
while (i < length) { |
| 2286 |
var rawChild = rawChildNodes[i]; |
| 2287 |
if (rawChild.nodeType === 8) { |
| 2288 |
if (rawChild.data === '!') { |
| 2289 |
var placeholder = document.createTextNode(''); |
| 2290 |
dom.replaceChild(placeholder, rawChild); |
| 2291 |
i++; |
| 2292 |
} |
| 2293 |
else { |
| 2294 |
dom.removeChild(rawChild); |
| 2295 |
length--; |
| 2296 |
} |
| 2297 |
} |
| 2298 |
else { |
| 2299 |
i++; |
| 2300 |
} |
| 2301 |
} |
| 2302 |
} |
| 2303 |
function hydrateComponent(vNode, dom, lifecycle, context, isSVG, isClass) { |
| 2304 |
var type = vNode.type; |
| 2305 |
var props = vNode.props || {}; |
| 2306 |
var ref = vNode.ref; |
| 2307 |
vNode.dom = dom; |
| 2308 |
if (isClass) { |
| 2309 |
var _isSVG = dom.namespaceURI === svgNS; |
| 2310 |
var defaultProps = type.defaultProps; |
| 2311 |
lifecycle.fastUnmount = false; |
| 2312 |
if (!isUndefined(defaultProps)) { |
| 2313 |
copyPropsTo(defaultProps, props); |
| 2314 |
vNode.props = props; |
| 2315 |
} |
| 2316 |
var instance = createStatefulComponentInstance(vNode, type, props, context, _isSVG, devToolsStatus); |
| 2317 |
var input = instance._lastInput; |
| 2318 |
var fastUnmount = lifecycle.fastUnmount; |
| 2319 |
// we store the fastUnmount value, but we set it back to true on the lifecycle |
| 2320 |
// we do this so we can determine if the component render has a fastUnmount or not |
| 2321 |
lifecycle.fastUnmount = true; |
| 2322 |
instance._vComponent = vNode; |
| 2323 |
instance._vNode = vNode; |
| 2324 |
hydrate(input, dom, lifecycle, instance._childContext, _isSVG); |
| 2325 |
var subLifecycle = instance._lifecycle = new Lifecycle(); |
| 2326 |
subLifecycle.fastUnmount = lifecycle.fastUnmount; |
| 2327 |
// we then set the lifecycle fastUnmount value back to what it was before the mount |
| 2328 |
lifecycle.fastUnmount = fastUnmount; |
| 2329 |
mountStatefulComponentCallbacks(ref, instance, lifecycle); |
| 2330 |
findDOMNodeEnabled && componentToDOMNodeMap.set(instance, dom); |
| 2331 |
vNode.children = instance; |
| 2332 |
} |
| 2333 |
else { |
| 2334 |
var input$1 = createStatelessComponentInput(vNode, type, props, context); |
| 2335 |
hydrate(input$1, dom, lifecycle, context, isSVG); |
| 2336 |
vNode.children = input$1; |
| 2337 |
vNode.dom = input$1.dom; |
| 2338 |
mountStatelessComponentCallbacks(ref, dom, lifecycle); |
| 2339 |
} |
| 2340 |
} |
| 2341 |
function hydrateElement(vNode, dom, lifecycle, context, isSVG) { |
| 2342 |
var tag = vNode.type; |
| 2343 |
var children = vNode.children; |
| 2344 |
var props = vNode.props; |
| 2345 |
var events = vNode.events; |
| 2346 |
var flags = vNode.flags; |
| 2347 |
if (isSVG || (flags & 128 /* SvgElement */)) { |
| 2348 |
isSVG = true; |
| 2349 |
} |
| 2350 |
if (dom.nodeType !== 1 || dom.tagName.toLowerCase() !== tag) { |
| 2351 |
var newDom = mountElement(vNode, null, lifecycle, context, isSVG); |
| 2352 |
vNode.dom = newDom; |
| 2353 |
replaceChild(dom.parentNode, newDom, dom); |
| 2354 |
} |
| 2355 |
else { |
| 2356 |
vNode.dom = dom; |
| 2357 |
if (children) { |
| 2358 |
hydrateChildren(children, dom, lifecycle, context, isSVG); |
| 2359 |
} |
| 2360 |
if (!(flags & 2 /* HtmlElement */)) { |
| 2361 |
processElement(flags, vNode, dom); |
| 2362 |
} |
| 2363 |
for (var prop in props) { |
| 2364 |
patchProp(prop, null, props[prop], dom, isSVG, lifecycle); |
| 2365 |
} |
| 2366 |
for (var name in events) { |
| 2367 |
patchEvent(name, null, events[name], dom, lifecycle); |
| 2368 |
} |
| 2369 |
} |
| 2370 |
} |
| 2371 |
function hydrateChildren(children, dom, lifecycle, context, isSVG) { |
| 2372 |
normaliseChildNodes(dom); |
| 2373 |
var domNodes = Array.prototype.slice.call(dom.childNodes); |
| 2374 |
var childNodeIndex = 0; |
| 2375 |
if (isArray(children)) { |
| 2376 |
for (var i = 0; i < children.length; i++) { |
| 2377 |
var child = children[i]; |
| 2378 |
if (isObject(child) && !isNull(child)) { |
| 2379 |
hydrate(child, domNodes[childNodeIndex++], lifecycle, context, isSVG); |
| 2380 |
} |
| 2381 |
} |
| 2382 |
} |
| 2383 |
else if (isObject(children)) { |
| 2384 |
hydrate(children, dom.firstChild, lifecycle, context, isSVG); |
| 2385 |
} |
| 2386 |
} |
| 2387 |
function hydrateText(vNode, dom) { |
| 2388 |
if (dom.nodeType === 3) { |
| 2389 |
var newDom = mountText(vNode, null); |
| 2390 |
vNode.dom = newDom; |
| 2391 |
replaceChild(dom.parentNode, newDom, dom); |
| 2392 |
} |
| 2393 |
else { |
| 2394 |
vNode.dom = dom; |
| 2395 |
} |
| 2396 |
} |
| 2397 |
function hydrateVoid(vNode, dom) { |
| 2398 |
vNode.dom = dom; |
| 2399 |
} |
| 2400 |
function hydrate(vNode, dom, lifecycle, context, isSVG) { |
| 2401 |
if (false) { |
| 2402 |
if (isInvalid(dom)) { |
| 2403 |
throwError("failed to hydrate. The server-side render doesn't match client side."); |
| 2404 |
} |
| 2405 |
} |
| 2406 |
var flags = vNode.flags; |
| 2407 |
if (flags & 28 /* Component */) { |
| 2408 |
return hydrateComponent(vNode, dom, lifecycle, context, isSVG, flags & 4 /* ComponentClass */); |
| 2409 |
} |
| 2410 |
else if (flags & 3970 /* Element */) { |
| 2411 |
return hydrateElement(vNode, dom, lifecycle, context, isSVG); |
| 2412 |
} |
| 2413 |
else if (flags & 1 /* Text */) { |
| 2414 |
return hydrateText(vNode, dom); |
| 2415 |
} |
| 2416 |
else if (flags & 4096 /* Void */) { |
| 2417 |
return hydrateVoid(vNode, dom); |
| 2418 |
} |
| 2419 |
else { |
| 2420 |
if (false) { |
| 2421 |
throwError(("hydrate() expects a valid VNode, instead it received an object with the type \"" + (typeof vNode) + "\".")); |
| 2422 |
} |
| 2423 |
throwError(); |
| 2424 |
} |
| 2425 |
} |
| 2426 |
function hydrateRoot(input, parentDom, lifecycle) { |
| 2427 |
if (parentDom && parentDom.nodeType === 1 && parentDom.firstChild) { |
| 2428 |
hydrate(input, parentDom.firstChild, lifecycle, {}, false); |
| 2429 |
return true; |
| 2430 |
} |
| 2431 |
return false; |
| 2432 |
} |
| 2433 |
|
| 2434 |
// rather than use a Map, like we did before, we can use an array here |
| 2435 |
// given there shouldn't be THAT many roots on the page, the difference |
| 2436 |
// in performance is huge: https://esbench.com/bench/5802a691330ab09900a1a2da |
| 2437 |
var roots = []; |
| 2438 |
var componentToDOMNodeMap = new Map(); |
| 2439 |
var findDOMNodeEnabled = false; |
| 2440 |
function enableFindDOMNode() { |
| 2441 |
findDOMNodeEnabled = true; |
| 2442 |
} |
| 2443 |
function findDOMNode(ref) { |
| 2444 |
if (!findDOMNodeEnabled) { |
| 2445 |
if (false) { |
| 2446 |
throwError('findDOMNode() has been disabled, use enableFindDOMNode() enabled findDOMNode(). Warning this can significantly impact performance!'); |
| 2447 |
} |
| 2448 |
throwError(); |
| 2449 |
} |
| 2450 |
var dom = ref && ref.nodeType ? ref : null; |
| 2451 |
return componentToDOMNodeMap.get(ref) || dom; |
| 2452 |
} |
| 2453 |
function getRoot(dom) { |
| 2454 |
for (var i = 0; i < roots.length; i++) { |
| 2455 |
var root = roots[i]; |
| 2456 |
if (root.dom === dom) { |
| 2457 |
return root; |
| 2458 |
} |
| 2459 |
} |
| 2460 |
return null; |
| 2461 |
} |
| 2462 |
function setRoot(dom, input, lifecycle) { |
| 2463 |
roots.push({ |
| 2464 |
dom: dom, |
| 2465 |
input: input, |
| 2466 |
lifecycle: lifecycle |
| 2467 |
}); |
| 2468 |
} |
| 2469 |
function removeRoot(root) { |
| 2470 |
for (var i = 0; i < roots.length; i++) { |
| 2471 |
if (roots[i] === root) { |
| 2472 |
roots.splice(i, 1); |
| 2473 |
return; |
| 2474 |
} |
| 2475 |
} |
| 2476 |
} |
| 2477 |
var documentBody = isBrowser ? document.body : null; |
| 2478 |
function render(input, parentDom) { |
| 2479 |
if (documentBody === parentDom) { |
| 2480 |
if (false) { |
| 2481 |
throwError('you cannot render() to the "document.body". Use an empty element as a container instead.'); |
| 2482 |
} |
| 2483 |
throwError(); |
| 2484 |
} |
| 2485 |
if (input === NO_OP) { |
| 2486 |
return; |
| 2487 |
} |
| 2488 |
var root = getRoot(parentDom); |
| 2489 |
if (isNull(root)) { |
| 2490 |
var lifecycle = new Lifecycle(); |
| 2491 |
if (!isInvalid(input)) { |
| 2492 |
if (input.dom) { |
| 2493 |
input = cloneVNode(input); |
| 2494 |
} |
| 2495 |
if (!hydrateRoot(input, parentDom, lifecycle)) { |
| 2496 |
mount(input, parentDom, lifecycle, {}, false); |
| 2497 |
} |
| 2498 |
lifecycle.trigger(); |
| 2499 |
setRoot(parentDom, input, lifecycle); |
| 2500 |
} |
| 2501 |
} |
| 2502 |
else { |
| 2503 |
var lifecycle$1 = root.lifecycle; |
| 2504 |
lifecycle$1.listeners = []; |
| 2505 |
if (isNullOrUndef(input)) { |
| 2506 |
unmount(root.input, parentDom, lifecycle$1, false, false, false); |
| 2507 |
removeRoot(root); |
| 2508 |
} |
| 2509 |
else { |
| 2510 |
if (input.dom) { |
| 2511 |
input = cloneVNode(input); |
| 2512 |
} |
| 2513 |
patch(root.input, input, parentDom, lifecycle$1, {}, false, false); |
| 2514 |
} |
| 2515 |
lifecycle$1.trigger(); |
| 2516 |
root.input = input; |
| 2517 |
} |
| 2518 |
if (devToolsStatus.connected) { |
| 2519 |
sendRoots(window); |
| 2520 |
} |
| 2521 |
} |
| 2522 |
function createRenderer() { |
| 2523 |
var parentDom; |
| 2524 |
return function renderer(lastInput, nextInput) { |
| 2525 |
if (!parentDom) { |
| 2526 |
parentDom = lastInput; |
| 2527 |
} |
| 2528 |
render(nextInput, parentDom); |
| 2529 |
}; |
| 2530 |
} |
| 2531 |
|
| 2532 |
function linkEvent(data, event) { |
| 2533 |
return { data: data, event: event }; |
| 2534 |
} |
| 2535 |
|
| 2536 |
if (isBrowser) { |
| 2537 |
window.process = { |
| 2538 |
env: { |
| 2539 |
NODE_ENV: 'development' |
| 2540 |
} |
| 2541 |
}; |
| 2542 |
initDevToolsHooks(window); |
| 2543 |
} |
| 2544 |
|
| 2545 |
if (false) { |
| 2546 |
var testFunc = function testFn() {}; |
| 2547 |
warning( |
| 2548 |
(testFunc.name || testFunc.toString()).indexOf('testFn') !== -1, |
| 2549 |
'It looks like you\'re using a minified copy of the development build ' + |
| 2550 |
'of Inferno. When deploying Inferno apps to production, make sure to use ' + |
| 2551 |
'the production build which skips development warnings and is faster. ' + |
| 2552 |
'See http://infernojs.org for more details.' |
| 2553 |
); |
| 2554 |
} |
| 2555 |
|
| 2556 |
// we duplicate it so it plays nicely with different module loading systems |
| 2557 |
var index = { |
| 2558 |
linkEvent: linkEvent, |
| 2559 |
// core shapes |
| 2560 |
createVNode: createVNode, |
| 2561 |
|
| 2562 |
// cloning |
| 2563 |
cloneVNode: cloneVNode, |
| 2564 |
|
| 2565 |
// used to shared common items between Inferno libs |
| 2566 |
NO_OP: NO_OP, |
| 2567 |
EMPTY_OBJ: EMPTY_OBJ, |
| 2568 |
|
| 2569 |
//DOM |
| 2570 |
render: render, |
| 2571 |
findDOMNode: findDOMNode, |
| 2572 |
createRenderer: createRenderer, |
| 2573 |
disableRecycling: disableRecycling, |
| 2574 |
enableFindDOMNode: enableFindDOMNode |
| 2575 |
}; |
| 2576 |
|
| 2577 |
exports['default'] = index; |
| 2578 |
exports.linkEvent = linkEvent; |
| 2579 |
exports.createVNode = createVNode; |
| 2580 |
exports.cloneVNode = cloneVNode; |
| 2581 |
exports.NO_OP = NO_OP; |
| 2582 |
exports.EMPTY_OBJ = EMPTY_OBJ; |
| 2583 |
exports.render = render; |
| 2584 |
exports.findDOMNode = findDOMNode; |
| 2585 |
exports.createRenderer = createRenderer; |
| 2586 |
exports.disableRecycling = disableRecycling; |
| 2587 |
exports.enableFindDOMNode = enableFindDOMNode; |
| 2588 |
|
| 2589 |
Object.defineProperty(exports, '__esModule', { value: true }); |
| 2590 |
|
| 2591 |
}))); |
| 2592 |
|
| 2593 |
|
| 2594 |
/***/ }, |
| 2595 |
/* 3 */ |
| 2596 |
/***/ function(module, exports, __webpack_require__) { |
| 2597 |
|
| 2598 |
module.exports = __webpack_require__(4); |
| 2599 |
|
| 2600 |
|
| 2601 |
/***/ }, |
| 2602 |
/* 4 */ |
| 2603 |
/***/ function(module, exports, __webpack_require__) { |
| 2604 |
|
| 2605 |
/*! |
| 2606 |
* inferno-component v1.0.0-beta32 |
| 2607 |
* (c) 2016 Dominic Gannaway |
| 2608 |
* Released under the MIT License. |
| 2609 |
*/ |
| 2610 |
(function (global, factory) { |
| 2611 |
true ? module.exports = factory(__webpack_require__(2)) : |
| 2612 |
typeof define === 'function' && define.amd ? define(['inferno'], factory) : |
| 2613 |
(global.Inferno = global.Inferno || {}, global.Inferno.Component = factory(global.Inferno)); |
| 2614 |
}(this, (function (inferno) { 'use strict'; |
| 2615 |
|
| 2616 |
var ERROR_MSG = 'a runtime error occured! Use Inferno in development environment to find the error.'; |
| 2617 |
|
| 2618 |
|
| 2619 |
// this is MUCH faster than .constructor === Array and instanceof Array |
| 2620 |
// in Node 7 and the later versions of V8, slower in older versions though |
| 2621 |
var isArray = Array.isArray; |
| 2622 |
|
| 2623 |
|
| 2624 |
function isNullOrUndef(obj) { |
| 2625 |
return isUndefined(obj) || isNull(obj); |
| 2626 |
} |
| 2627 |
function isInvalid(obj) { |
| 2628 |
return isNull(obj) || obj === false || isTrue(obj) || isUndefined(obj); |
| 2629 |
} |
| 2630 |
function isFunction(obj) { |
| 2631 |
return typeof obj === 'function'; |
| 2632 |
} |
| 2633 |
|
| 2634 |
|
| 2635 |
|
| 2636 |
function isNull(obj) { |
| 2637 |
return obj === null; |
| 2638 |
} |
| 2639 |
function isTrue(obj) { |
| 2640 |
return obj === true; |
| 2641 |
} |
| 2642 |
function isUndefined(obj) { |
| 2643 |
return obj === undefined; |
| 2644 |
} |
| 2645 |
|
| 2646 |
function throwError(message) { |
| 2647 |
if (!message) { |
| 2648 |
message = ERROR_MSG; |
| 2649 |
} |
| 2650 |
throw new Error(("Inferno Error: " + message)); |
| 2651 |
} |
| 2652 |
|
| 2653 |
var Lifecycle = function Lifecycle() { |
| 2654 |
this.listeners = []; |
| 2655 |
this.fastUnmount = true; |
| 2656 |
}; |
| 2657 |
Lifecycle.prototype.addListener = function addListener (callback) { |
| 2658 |
this.listeners.push(callback); |
| 2659 |
}; |
| 2660 |
Lifecycle.prototype.trigger = function trigger () { |
| 2661 |
var this$1 = this; |
| 2662 |
|
| 2663 |
for (var i = 0; i < this.listeners.length; i++) { |
| 2664 |
this$1.listeners[i](); |
| 2665 |
} |
| 2666 |
}; |
| 2667 |
|
| 2668 |
var noOp = ERROR_MSG; |
| 2669 |
if (false) { |
| 2670 |
noOp = 'Inferno Error: Can only update a mounted or mounting component. This usually means you called setState() or forceUpdate() on an unmounted component. This is a no-op.'; |
| 2671 |
} |
| 2672 |
var componentCallbackQueue = new Map(); |
| 2673 |
// when a components root VNode is also a component, we can run into issues |
| 2674 |
// this will recursively look for vNode.parentNode if the VNode is a component |
| 2675 |
function updateParentComponentVNodes(vNode, dom) { |
| 2676 |
if (vNode.flags & 28 /* Component */) { |
| 2677 |
var parentVNode = vNode.parentVNode; |
| 2678 |
if (parentVNode) { |
| 2679 |
parentVNode.dom = dom; |
| 2680 |
updateParentComponentVNodes(parentVNode, dom); |
| 2681 |
} |
| 2682 |
} |
| 2683 |
} |
| 2684 |
// this is in shapes too, but we don't want to import from shapes as it will pull in a duplicate of createVNode |
| 2685 |
function createVoidVNode() { |
| 2686 |
return inferno.createVNode(4096 /* Void */); |
| 2687 |
} |
| 2688 |
function addToQueue(component, force, callback) { |
| 2689 |
// TODO this function needs to be revised and improved on |
| 2690 |
var queue = componentCallbackQueue.get(component); |
| 2691 |
if (!queue) { |
| 2692 |
queue = []; |
| 2693 |
componentCallbackQueue.set(component, queue); |
| 2694 |
Promise.resolve().then(function () { |
| 2695 |
applyState(component, force, function () { |
| 2696 |
for (var i = 0; i < queue.length; i++) { |
| 2697 |
queue[i](); |
| 2698 |
} |
| 2699 |
}); |
| 2700 |
componentCallbackQueue.delete(component); |
| 2701 |
component._processingSetState = false; |
| 2702 |
}); |
| 2703 |
} |
| 2704 |
if (callback) { |
| 2705 |
queue.push(callback); |
| 2706 |
} |
| 2707 |
} |
| 2708 |
function queueStateChanges(component, newState, callback) { |
| 2709 |
if (isFunction(newState)) { |
| 2710 |
newState = newState(component.state); |
| 2711 |
} |
| 2712 |
for (var stateKey in newState) { |
| 2713 |
component._pendingState[stateKey] = newState[stateKey]; |
| 2714 |
} |
| 2715 |
if (!component._pendingSetState) { |
| 2716 |
if (component._processingSetState || callback) { |
| 2717 |
addToQueue(component, false, callback); |
| 2718 |
} |
| 2719 |
else { |
| 2720 |
component._pendingSetState = true; |
| 2721 |
component._processingSetState = true; |
| 2722 |
applyState(component, false, callback); |
| 2723 |
component._processingSetState = false; |
| 2724 |
} |
| 2725 |
} |
| 2726 |
else { |
| 2727 |
component.state = Object.assign({}, component.state, component._pendingState); |
| 2728 |
component._pendingState = {}; |
| 2729 |
} |
| 2730 |
} |
| 2731 |
function applyState(component, force, callback) { |
| 2732 |
if ((!component._deferSetState || force) && !component._blockRender) { |
| 2733 |
component._pendingSetState = false; |
| 2734 |
var pendingState = component._pendingState; |
| 2735 |
var prevState = component.state; |
| 2736 |
var nextState = Object.assign({}, prevState, pendingState); |
| 2737 |
var props = component.props; |
| 2738 |
var context = component.context; |
| 2739 |
component._pendingState = {}; |
| 2740 |
var nextInput = component._updateComponent(prevState, nextState, props, props, context, force); |
| 2741 |
var didUpdate = true; |
| 2742 |
if (isInvalid(nextInput)) { |
| 2743 |
nextInput = createVoidVNode(); |
| 2744 |
} |
| 2745 |
else if (isArray(nextInput)) { |
| 2746 |
if (false) { |
| 2747 |
throwError('a valid Inferno VNode (or null) must be returned from a component render. You may have returned an array or an invalid object.'); |
| 2748 |
} |
| 2749 |
throwError(); |
| 2750 |
} |
| 2751 |
else if (nextInput === inferno.NO_OP) { |
| 2752 |
nextInput = component._lastInput; |
| 2753 |
didUpdate = false; |
| 2754 |
} |
| 2755 |
var lastInput = component._lastInput; |
| 2756 |
var parentDom = lastInput.dom.parentNode; |
| 2757 |
component._lastInput = nextInput; |
| 2758 |
if (didUpdate) { |
| 2759 |
var subLifecycle = component._lifecycle; |
| 2760 |
if (!subLifecycle) { |
| 2761 |
subLifecycle = new Lifecycle(); |
| 2762 |
} |
| 2763 |
else { |
| 2764 |
subLifecycle.listeners = []; |
| 2765 |
} |
| 2766 |
component._lifecycle = subLifecycle; |
| 2767 |
var childContext = component.getChildContext(); |
| 2768 |
if (!isNullOrUndef(childContext)) { |
| 2769 |
childContext = Object.assign({}, context, component._childContext, childContext); |
| 2770 |
} |
| 2771 |
else { |
| 2772 |
childContext = Object.assign({}, context, component._childContext); |
| 2773 |
} |
| 2774 |
component._patch(lastInput, nextInput, parentDom, subLifecycle, childContext, component._isSVG, false); |
| 2775 |
subLifecycle.trigger(); |
| 2776 |
component.componentDidUpdate(props, prevState); |
| 2777 |
} |
| 2778 |
var vNode = component._vNode; |
| 2779 |
var dom = vNode.dom = nextInput.dom; |
| 2780 |
var componentToDOMNodeMap = component._componentToDOMNodeMap; |
| 2781 |
componentToDOMNodeMap && componentToDOMNodeMap.set(component, nextInput.dom); |
| 2782 |
updateParentComponentVNodes(vNode, dom); |
| 2783 |
if (!isNullOrUndef(callback)) { |
| 2784 |
callback(); |
| 2785 |
} |
| 2786 |
} |
| 2787 |
} |
| 2788 |
var Component$1 = function Component$1(props, context) { |
| 2789 |
this.state = {}; |
| 2790 |
this.refs = {}; |
| 2791 |
this._processingSetState = false; |
| 2792 |
this._blockRender = false; |
| 2793 |
this._ignoreSetState = false; |
| 2794 |
this._blockSetState = false; |
| 2795 |
this._deferSetState = false; |
| 2796 |
this._pendingSetState = false; |
| 2797 |
this._pendingState = {}; |
| 2798 |
this._lastInput = null; |
| 2799 |
this._vNode = null; |
| 2800 |
this._unmounted = true; |
| 2801 |
this._devToolsStatus = null; |
| 2802 |
this._devToolsId = null; |
| 2803 |
this._lifecycle = null; |
| 2804 |
this._childContext = null; |
| 2805 |
this._patch = null; |
| 2806 |
this._isSVG = false; |
| 2807 |
this._componentToDOMNodeMap = null; |
| 2808 |
/** @type {object} */ |
| 2809 |
this.props = props || inferno.EMPTY_OBJ; |
| 2810 |
/** @type {object} */ |
| 2811 |
this.context = context || {}; |
| 2812 |
if (!this.componentDidMount) { |
| 2813 |
this.componentDidMount = null; |
| 2814 |
} |
| 2815 |
}; |
| 2816 |
Component$1.prototype.render = function render (nextProps, nextState, nextContext) { |
| 2817 |
}; |
| 2818 |
Component$1.prototype.forceUpdate = function forceUpdate (callback) { |
| 2819 |
if (this._unmounted) { |
| 2820 |
throw Error(noOp); |
| 2821 |
} |
| 2822 |
applyState(this, true, callback); |
| 2823 |
}; |
| 2824 |
Component$1.prototype.setState = function setState (newState, callback) { |
| 2825 |
if (this._unmounted) { |
| 2826 |
throw Error(noOp); |
| 2827 |
} |
| 2828 |
if (!this._blockSetState) { |
| 2829 |
if (!this._ignoreSetState) { |
| 2830 |
queueStateChanges(this, newState, callback); |
| 2831 |
} |
| 2832 |
} |
| 2833 |
else { |
| 2834 |
if (false) { |
| 2835 |
throwError('cannot update state via setState() in componentWillUpdate().'); |
| 2836 |
} |
| 2837 |
throwError(); |
| 2838 |
} |
| 2839 |
}; |
| 2840 |
Component$1.prototype.componentWillMount = function componentWillMount () { |
| 2841 |
}; |
| 2842 |
Component$1.prototype.componentDidMount = function componentDidMount () { |
| 2843 |
}; |
| 2844 |
Component$1.prototype.componentWillUnmount = function componentWillUnmount () { |
| 2845 |
}; |
| 2846 |
Component$1.prototype.componentDidUpdate = function componentDidUpdate (prevProps, prevState, prevContext) { |
| 2847 |
}; |
| 2848 |
Component$1.prototype.shouldComponentUpdate = function shouldComponentUpdate (nextProps, nextState, context) { |
| 2849 |
return true; |
| 2850 |
}; |
| 2851 |
Component$1.prototype.componentWillReceiveProps = function componentWillReceiveProps (nextProps, context) { |
| 2852 |
}; |
| 2853 |
Component$1.prototype.componentWillUpdate = function componentWillUpdate (nextProps, nextState, nextContext) { |
| 2854 |
}; |
| 2855 |
Component$1.prototype.getChildContext = function getChildContext () { |
| 2856 |
}; |
| 2857 |
Component$1.prototype._updateComponent = function _updateComponent (prevState, nextState, prevProps, nextProps, context, force) { |
| 2858 |
if (this._unmounted === true) { |
| 2859 |
if (false) { |
| 2860 |
throwError(noOp); |
| 2861 |
} |
| 2862 |
throwError(); |
| 2863 |
} |
| 2864 |
if ((prevProps !== nextProps || nextProps === inferno.EMPTY_OBJ) || prevState !== nextState || force) { |
| 2865 |
if (prevProps !== nextProps || nextProps === inferno.EMPTY_OBJ) { |
| 2866 |
this._blockRender = true; |
| 2867 |
this.componentWillReceiveProps(nextProps, context); |
| 2868 |
this._blockRender = false; |
| 2869 |
if (this._pendingSetState) { |
| 2870 |
nextState = Object.assign({}, nextState, this._pendingState); |
| 2871 |
this._pendingSetState = false; |
| 2872 |
this._pendingState = {}; |
| 2873 |
} |
| 2874 |
} |
| 2875 |
var shouldUpdate = this.shouldComponentUpdate(nextProps, nextState, context); |
| 2876 |
if (shouldUpdate !== false || force) { |
| 2877 |
this._blockSetState = true; |
| 2878 |
this.componentWillUpdate(nextProps, nextState, context); |
| 2879 |
this._blockSetState = false; |
| 2880 |
this.props = nextProps; |
| 2881 |
var state = this.state = nextState; |
| 2882 |
this.context = context; |
| 2883 |
this._beforeRender && this._beforeRender(); |
| 2884 |
var render = this.render(nextProps, state, context); |
| 2885 |
this._afterRender && this._afterRender(); |
| 2886 |
return render; |
| 2887 |
} |
| 2888 |
} |
| 2889 |
return inferno.NO_OP; |
| 2890 |
}; |
| 2891 |
|
| 2892 |
return Component$1; |
| 2893 |
|
| 2894 |
}))); |
| 2895 |
|
| 2896 |
|
| 2897 |
/***/ }, |
| 2898 |
/* 5 */ |
| 2899 |
/***/ function(module, exports) { |
| 2900 |
|
| 2901 |
'use strict'; |
| 2902 |
|
| 2903 |
exports.__esModule = true; |
| 2904 |
exports.read = read; |
| 2905 |
exports.assign = assign; |
| 2906 |
exports.isEqual = isEqual; |
| 2907 |
/** |
| 2908 |
* Shared funcs/values |
| 2909 |
*/ |
| 2910 |
|
| 2911 |
var ENTER = exports.ENTER = 13; |
| 2912 |
var ESCAPE = exports.ESCAPE = 27; |
| 2913 |
|
| 2914 |
var filters = exports.filters = { |
| 2915 |
all: function all(t) { |
| 2916 |
return true; |
| 2917 |
}, |
| 2918 |
active: function active(t) { |
| 2919 |
return !t.completed; |
| 2920 |
}, |
| 2921 |
completed: function completed(t) { |
| 2922 |
return t.completed; |
| 2923 |
} |
| 2924 |
}; |
| 2925 |
|
| 2926 |
/** |
| 2927 |
* Read the `location.hash` value |
| 2928 |
* @return {String} |
| 2929 |
*/ |
| 2930 |
function read() { |
| 2931 |
return location.hash.replace('#/', '') || 'all'; |
| 2932 |
} |
| 2933 |
|
| 2934 |
/** |
| 2935 |
* Modified `Object.assign` shim |
| 2936 |
* - always writes to new object |
| 2937 |
* @return {Object} |
| 2938 |
*/ |
| 2939 |
function assign() { |
| 2940 |
var src = void 0; |
| 2941 |
var tar = {}; |
| 2942 |
for (var s = 0; s < arguments.length; s++) { |
| 2943 |
src = Object(arguments[s]); |
| 2944 |
for (var k in src) { |
| 2945 |
tar[k] = src[k]; |
| 2946 |
} |
| 2947 |
} |
| 2948 |
return tar; |
| 2949 |
} |
| 2950 |
|
| 2951 |
/** |
| 2952 |
* Are two Objects equal values? |
| 2953 |
* @param {Object} a |
| 2954 |
* @param {Object} b |
| 2955 |
* @return {Boolean} |
| 2956 |
*/ |
| 2957 |
function isEqual(a, b) { |
| 2958 |
// Create arrays of property names |
| 2959 |
var aProps = Object.getOwnPropertyNames(a); |
| 2960 |
var bProps = Object.getOwnPropertyNames(b); |
| 2961 |
|
| 2962 |
if (aProps.length !== bProps.length) return false; |
| 2963 |
|
| 2964 |
for (var i = 0; i < aProps.length; i++) { |
| 2965 |
var k = aProps[i]; |
| 2966 |
if (a[k] !== b[k]) return false; |
| 2967 |
} |
| 2968 |
|
| 2969 |
return true; |
| 2970 |
} |
| 2971 |
|
| 2972 |
/***/ }, |
| 2973 |
/* 6 */ |
| 2974 |
/***/ function(module, exports, __webpack_require__) { |
| 2975 |
|
| 2976 |
'use strict'; |
| 2977 |
|
| 2978 |
exports.__esModule = true; |
| 2979 |
exports.links = undefined; |
| 2980 |
exports.Head = Head; |
| 2981 |
exports.Foot = Foot; |
| 2982 |
|
| 2983 |
var _inferno = __webpack_require__(1); |
| 2984 |
|
| 2985 |
var _inferno2 = _interopRequireDefault(_inferno); |
| 2986 |
|
| 2987 |
var _share = __webpack_require__(5); |
| 2988 |
|
| 2989 |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
| 2990 |
|
| 2991 |
/** |
| 2992 |
* Stateless Header component |
| 2993 |
*/ |
| 2994 |
function Head(_ref) { |
| 2995 |
var onEnter = _ref.onEnter; |
| 2996 |
|
| 2997 |
return _inferno2.default.createVNode(2, 'header', { |
| 2998 |
'className': 'header' |
| 2999 |
}, [_inferno2.default.createVNode(2, 'h1', null, 'todos'), _inferno2.default.createVNode(512, 'input', { |
| 3000 |
'className': 'new-todo', |
| 3001 |
'autofocus': true, |
| 3002 |
'autocomplete': 'off', |
| 3003 |
'placeholder': 'What needs to be done?' |
| 3004 |
}, null, { |
| 3005 |
'onkeydown': onEnter |
| 3006 |
})]); |
| 3007 |
} |
| 3008 |
|
| 3009 |
var links = exports.links = [{ hash: '#/', name: 'All' }, { hash: '#/active', name: 'Active' }, { hash: '#/completed', name: 'Completed' }]; |
| 3010 |
|
| 3011 |
/** |
| 3012 |
* Stateless Footer component |
| 3013 |
*/ |
| 3014 |
function Foot(_ref2) { |
| 3015 |
var left = _ref2.left, |
| 3016 |
done = _ref2.done, |
| 3017 |
route = _ref2.route, |
| 3018 |
onClear = _ref2.onClear; |
| 3019 |
|
| 3020 |
return _inferno2.default.createVNode(2, 'footer', { |
| 3021 |
'className': 'footer' |
| 3022 |
}, [_inferno2.default.createVNode(2, 'span', { |
| 3023 |
'className': 'todo-count' |
| 3024 |
}, [_inferno2.default.createVNode(2, 'strong', null, left), ' ', left > 1 ? 'items' : 'item', ' left']), _inferno2.default.createVNode(2, 'ul', { |
| 3025 |
'className': 'filters' |
| 3026 |
}, links.map(function (_ref3) { |
| 3027 |
var hash = _ref3.hash, |
| 3028 |
name = _ref3.name; |
| 3029 |
return _inferno2.default.createVNode(2, 'li', null, _inferno2.default.createVNode(2, 'a', { |
| 3030 |
'href': hash, |
| 3031 |
'className': name.toLowerCase() === route ? 'selected' : '' |
| 3032 |
}, name)); |
| 3033 |
})), done > 0 ? _inferno2.default.createVNode(2, 'button', { |
| 3034 |
'className': 'clear-completed' |
| 3035 |
}, 'Clear completed', { |
| 3036 |
'onClick': onClear |
| 3037 |
}) : null]); |
| 3038 |
} |
| 3039 |
|
| 3040 |
/***/ }, |
| 3041 |
/* 7 */ |
| 3042 |
/***/ function(module, exports, __webpack_require__) { |
| 3043 |
|
| 3044 |
'use strict'; |
| 3045 |
|
| 3046 |
exports.__esModule = true; |
| 3047 |
|
| 3048 |
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; |
| 3049 |
|
| 3050 |
var _share = __webpack_require__(5); |
| 3051 |
|
| 3052 |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
| 3053 |
|
| 3054 |
var STOR = {}; |
| 3055 |
var STOR_ID = 'todos-inferno'; |
| 3056 |
|
| 3057 |
var Model = function Model() { |
| 3058 |
var _this = this; |
| 3059 |
|
| 3060 |
_classCallCheck(this, Model); |
| 3061 |
|
| 3062 |
this.get = function () { |
| 3063 |
return _this.data = JSON.parse(STOR[STOR_ID] || '[]'); |
| 3064 |
}; |
| 3065 |
|
| 3066 |
this.set = function (arr) { |
| 3067 |
_this.data = arr || _this.data || []; |
| 3068 |
STOR[STOR_ID] = JSON.stringify(_this.data); |
| 3069 |
return _this.data; |
| 3070 |
}; |
| 3071 |
|
| 3072 |
this.add = function (str) { |
| 3073 |
return _this.set(_this.data.concat({ title: str, completed: false })); |
| 3074 |
}; |
| 3075 |
|
| 3076 |
this.put = function (todo, obj) { |
| 3077 |
return _this.set(_this.data.map(function (t) { |
| 3078 |
return (0, _share.isEqual)(t, todo) ? (0, _share.assign)(todo, obj) : t; |
| 3079 |
})); |
| 3080 |
}; |
| 3081 |
|
| 3082 |
this.del = function (todo) { |
| 3083 |
return _this.set(_this.data.filter(function (t) { |
| 3084 |
return !(0, _share.isEqual)(t, todo); |
| 3085 |
})); |
| 3086 |
}; |
| 3087 |
|
| 3088 |
this.toggle = function (todo) { |
| 3089 |
return _this.put(todo, { completed: !todo.completed }); |
| 3090 |
}; |
| 3091 |
|
| 3092 |
this.toggleAll = function (completed) { |
| 3093 |
return _this.set(_this.data.map(function (t) { |
| 3094 |
return _extends({}, t, { completed: completed }); |
| 3095 |
})); |
| 3096 |
}; |
| 3097 |
|
| 3098 |
this.clearCompleted = function () { |
| 3099 |
return _this.set(_this.data.filter(function (t) { |
| 3100 |
return !t.completed; |
| 3101 |
})); |
| 3102 |
}; |
| 3103 |
}; |
| 3104 |
|
| 3105 |
exports.default = Model; |
| 3106 |
|
| 3107 |
/***/ }, |
| 3108 |
/* 8 */ |
| 3109 |
/***/ function(module, exports, __webpack_require__) { |
| 3110 |
|
| 3111 |
'use strict'; |
| 3112 |
|
| 3113 |
exports.__esModule = true; |
| 3114 |
|
| 3115 |
var _inferno = __webpack_require__(1); |
| 3116 |
|
| 3117 |
var _inferno2 = _interopRequireDefault(_inferno); |
| 3118 |
|
| 3119 |
var _infernoComponent = __webpack_require__(3); |
| 3120 |
|
| 3121 |
var _infernoComponent2 = _interopRequireDefault(_infernoComponent); |
| 3122 |
|
| 3123 |
var _share = __webpack_require__(5); |
| 3124 |
|
| 3125 |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
| 3126 |
|
| 3127 |
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } |
| 3128 |
|
| 3129 |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
| 3130 |
|
| 3131 |
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } |
| 3132 |
|
| 3133 |
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } |
| 3134 |
|
| 3135 |
var Item = function (_Component) { |
| 3136 |
_inherits(Item, _Component); |
| 3137 |
|
| 3138 |
function Item(_ref) { |
| 3139 |
var data = _ref.data, |
| 3140 |
props = _objectWithoutProperties(_ref, ['data']); |
| 3141 |
|
| 3142 |
_classCallCheck(this, Item); |
| 3143 |
|
| 3144 |
var _this = _possibleConstructorReturn(this, _Component.call(this, props)); |
| 3145 |
|
| 3146 |
_initialiseProps.call(_this); |
| 3147 |
|
| 3148 |
_this.todo = data; |
| 3149 |
_this.state = { text: data.title }; |
| 3150 |
_this.editor = null; |
| 3151 |
return _this; |
| 3152 |
} |
| 3153 |
|
| 3154 |
Item.prototype.render = function render(_ref2, _ref3) { |
| 3155 |
var _this2 = this; |
| 3156 |
|
| 3157 |
var doToggle = _ref2.doToggle, |
| 3158 |
doDelete = _ref2.doDelete, |
| 3159 |
doSave = _ref2.doSave, |
| 3160 |
onBlur = _ref2.onBlur, |
| 3161 |
onFocus = _ref2.onFocus; |
| 3162 |
var text = _ref3.text; |
| 3163 |
var _todo = this.todo, |
| 3164 |
title = _todo.title, |
| 3165 |
completed = _todo.completed, |
| 3166 |
editing = _todo.editing; |
| 3167 |
|
| 3168 |
|
| 3169 |
var cls = []; |
| 3170 |
editing && cls.push('editing'); |
| 3171 |
completed && cls.push('completed'); |
| 3172 |
|
| 3173 |
var handleKeydown = function handleKeydown(e) { |
| 3174 |
if (e.which === _share.ESCAPE) return onBlur(); |
| 3175 |
if (e.which === _share.ENTER) return doSave(text); |
| 3176 |
}; |
| 3177 |
|
| 3178 |
// tmp fix |
| 3179 |
var handleBlur = function handleBlur() { |
| 3180 |
return doSave(text); |
| 3181 |
}; |
| 3182 |
var handleInput = function handleInput(e) { |
| 3183 |
return _this2.setText(e.target.value); |
| 3184 |
}; |
| 3185 |
|
| 3186 |
return _inferno2.default.createVNode(2, 'li', { |
| 3187 |
'className': cls.join(' ') |
| 3188 |
}, [_inferno2.default.createVNode(2, 'div', { |
| 3189 |
'className': 'view' |
| 3190 |
}, [_inferno2.default.createVNode(512, 'input', { |
| 3191 |
'className': 'toggle', |
| 3192 |
'type': 'checkbox', |
| 3193 |
'checked': completed |
| 3194 |
}, null, { |
| 3195 |
'onClick': doToggle |
| 3196 |
}), _inferno2.default.createVNode(2, 'label', null, title, { |
| 3197 |
'ondblclick': onFocus |
| 3198 |
}), _inferno2.default.createVNode(2, 'button', { |
| 3199 |
'className': 'destroy' |
| 3200 |
}, null, { |
| 3201 |
'onClick': doDelete |
| 3202 |
})]), _inferno2.default.createVNode(512, 'input', { |
| 3203 |
'className': 'edit', |
| 3204 |
'value': editing && text |
| 3205 |
}, null, { |
| 3206 |
'onblur': handleBlur, |
| 3207 |
'oninput': handleInput, |
| 3208 |
'onkeydown': handleKeydown |
| 3209 |
}, null, function (el) { |
| 3210 |
_this2.editor = el; |
| 3211 |
})]); |
| 3212 |
}; |
| 3213 |
|
| 3214 |
return Item; |
| 3215 |
}(_infernoComponent2.default); |
| 3216 |
|
| 3217 |
var _initialiseProps = function _initialiseProps() { |
| 3218 |
var _this3 = this; |
| 3219 |
|
| 3220 |
this.componentWillReceiveProps = function (_ref4) { |
| 3221 |
var data = _ref4.data; |
| 3222 |
return _this3.setText(data.title); |
| 3223 |
}; |
| 3224 |
|
| 3225 |
this.shouldComponentUpdate = function (_ref5, _ref6) { |
| 3226 |
var data = _ref5.data; |
| 3227 |
var text = _ref6.text; |
| 3228 |
return !((0, _share.isEqual)(data, _this3.todo) && text === _this3.state.text); |
| 3229 |
}; |
| 3230 |
|
| 3231 |
this.componentWillUpdate = function (_ref7) { |
| 3232 |
var data = _ref7.data; |
| 3233 |
return _this3.todo = data; |
| 3234 |
}; |
| 3235 |
|
| 3236 |
this.componentDidUpdate = function () { |
| 3237 |
return _this3.editor.focus(); |
| 3238 |
}; |
| 3239 |
|
| 3240 |
this.setText = function (text) { |
| 3241 |
return _this3.setState({ text: text }); |
| 3242 |
}; |
| 3243 |
}; |
| 3244 |
|
| 3245 |
exports.default = Item; |
| 3246 |
|
| 3247 |
/***/ } |
| 3248 |
/******/ ]); |