Skip to content

Commit b040a52

Browse files
committed
fix(render): fix render not triggering correctly on alternating shallow and deep props change
1 parent 9b6780d commit b040a52

File tree

5 files changed

+1362
-1282
lines changed

5 files changed

+1362
-1282
lines changed

dist/easyState.js

Lines changed: 66 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
/******/ __webpack_require__.p = "";
6464
/******/
6565
/******/ // Load entry module and return exports
66-
/******/ return __webpack_require__(__webpack_require__.s = 53);
66+
/******/ return __webpack_require__(__webpack_require__.s = 34);
6767
/******/ })
6868
/************************************************************************/
6969
/******/ ({
@@ -72,7 +72,7 @@
7272
/***/ (function(module, __webpack_exports__, __webpack_require__) {
7373

7474
"use strict";
75-
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__observer__ = __webpack_require__(34);
75+
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__observer__ = __webpack_require__(53);
7676
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__internals__ = __webpack_require__(26);
7777
/* harmony export (immutable) */ __webpack_exports__["a"] = has;
7878
/* harmony export (immutable) */ __webpack_exports__["d"] = get;
@@ -246,6 +246,69 @@ const rawToProxy = new WeakMap()
246246
/***/ 34:
247247
/***/ (function(module, __webpack_exports__, __webpack_require__) {
248248

249+
"use strict";
250+
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
251+
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__nx_js_observer_util__ = __webpack_require__(86);
252+
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__autoBind__ = __webpack_require__(87);
253+
/* harmony export (immutable) */ __webpack_exports__["default"] = easyStateHOC;
254+
255+
256+
257+
const OBSERVED_RENDER = Symbol('observed render')
258+
const IS_DIRECT_RENDER = Symbol('is direct render')
259+
const RENDER_RESULT = Symbol('render result')
260+
261+
function easyStateHOC (WrappedComp) {
262+
return class EasyStateWrapper extends WrappedComp {
263+
constructor (props) {
264+
super(props)
265+
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__autoBind__["a" /* default */])(this, WrappedComp.prototype)
266+
this.state = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__nx_js_observer_util__["a" /* observable */])(this.state)
267+
}
268+
269+
render () {
270+
if (!this[OBSERVED_RENDER]) {
271+
this[OBSERVED_RENDER] = () => {
272+
if (this[IS_DIRECT_RENDER]) {
273+
this[RENDER_RESULT] = super.render()
274+
} else {
275+
super.forceUpdate()
276+
}
277+
}
278+
}
279+
280+
this[IS_DIRECT_RENDER] = true
281+
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__nx_js_observer_util__["b" /* observe */])(this[OBSERVED_RENDER])
282+
this[IS_DIRECT_RENDER] = false
283+
284+
return this[RENDER_RESULT]
285+
}
286+
287+
shouldComponentUpdate (nextProps) {
288+
const { props } = this
289+
const keys = Object.keys(props)
290+
const nextKeys = Object.keys(nextProps)
291+
292+
if (keys.length !== nextKeys.length) {
293+
return true
294+
}
295+
296+
for (let key of keys) {
297+
if (props[key] !== nextProps[key]) {
298+
return true
299+
}
300+
}
301+
return false
302+
}
303+
}
304+
}
305+
306+
307+
/***/ }),
308+
309+
/***/ 53:
310+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
311+
249312
"use strict";
250313
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__nextTick__ = __webpack_require__(93);
251314
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__builtIns_index__ = __webpack_require__(92);
@@ -408,72 +471,13 @@ function runObserver (observer) {
408471
}
409472

410473

411-
/***/ }),
412-
413-
/***/ 53:
414-
/***/ (function(module, __webpack_exports__, __webpack_require__) {
415-
416-
"use strict";
417-
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
418-
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__nx_js_observer_util__ = __webpack_require__(86);
419-
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__autoBind__ = __webpack_require__(87);
420-
/* harmony export (immutable) */ __webpack_exports__["default"] = easyStateHOC;
421-
422-
423-
424-
const OBSERVED_RENDER = Symbol('observed render')
425-
426-
function easyStateHOC (WrappedComp) {
427-
return class EasyStateWrapper extends WrappedComp {
428-
constructor (props) {
429-
super(props)
430-
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__autoBind__["a" /* default */])(this, WrappedComp.prototype)
431-
this.state = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__nx_js_observer_util__["a" /* observable */])(this.state)
432-
}
433-
434-
render () {
435-
if (this[OBSERVED_RENDER]) {
436-
return super.render()
437-
}
438-
439-
let result
440-
this[OBSERVED_RENDER] = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__nx_js_observer_util__["b" /* observe */])(() => {
441-
if (!this[OBSERVED_RENDER]) {
442-
result = super.render()
443-
} else {
444-
super.forceUpdate()
445-
}
446-
})
447-
return result
448-
}
449-
450-
shouldComponentUpdate (nextProps) {
451-
const { props } = this
452-
const keys = Object.keys(props)
453-
const nextKeys = Object.keys(nextProps)
454-
455-
if (keys.length !== nextKeys.length) {
456-
return true
457-
}
458-
459-
for (let key of keys) {
460-
if (props[key] !== nextProps[key]) {
461-
return true
462-
}
463-
}
464-
return false
465-
}
466-
}
467-
}
468-
469-
470474
/***/ }),
471475

472476
/***/ 86:
473477
/***/ (function(module, __webpack_exports__, __webpack_require__) {
474478

475479
"use strict";
476-
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__observer__ = __webpack_require__(34);
480+
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__observer__ = __webpack_require__(53);
477481
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return __WEBPACK_IMPORTED_MODULE_0__observer__["a"]; });
478482
/* unused harmony reexport isObservable */
479483
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return __WEBPACK_IMPORTED_MODULE_0__observer__["b"]; });

0 commit comments

Comments
 (0)