Comparing version 2.4.0 to 2.4.2
@@ -6,2 +6,13 @@ # Change Log | ||
## [2.4.2](https://github.com/zerkalica/urc/compare/v2.4.1...v2.4.2) (2019-03-13) | ||
### Bug Fixes | ||
* actions and props based cache reset ([c204370](https://github.com/zerkalica/urc/commit/c204370)) | ||
# [2.4.0](https://github.com/zerkalica/urc/compare/v2.3.0...v2.4.0) (2019-02-28) | ||
@@ -8,0 +19,0 @@ |
@@ -5,2 +5,24 @@ 'use strict'; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
function __decorate(decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
} | ||
function isFunctionComponent(OrigComponent) { | ||
@@ -10,4 +32,31 @@ return (!OrigComponent.prototype || | ||
} | ||
function reset_props(proto, name, descr) { | ||
return { | ||
configurable: true, | ||
enumerable: true, | ||
get() { | ||
return this.__props; | ||
}, | ||
set(v) { | ||
if (v !== this.__props && this.__atom !== undefined) | ||
this.__atom.reset(); | ||
this.__props = v; | ||
} | ||
}; | ||
} | ||
function reset_state(proto, name, descr) { | ||
return { | ||
configurable: true, | ||
enumerable: true, | ||
get() { | ||
return this.__state; | ||
}, | ||
set(v) { | ||
if (v !== this.__state && this.__atom !== undefined) | ||
this.__atom.reset(); | ||
this.__state = v; | ||
} | ||
}; | ||
} | ||
function createObserverComponent(ReactAtom, BaseComponent, renderError, OrigComponent) { | ||
var _a; | ||
const renderFunction = isFunctionComponent(OrigComponent) | ||
@@ -18,66 +67,66 @@ ? OrigComponent | ||
OrigComponent.name; | ||
const Cls = (_a = class extends (renderFunction | ||
? BaseComponent | ||
: OrigComponent) { | ||
constructor(props, context) { | ||
super(props, context); | ||
const id = (props && props.id) || | ||
this.constructor.displayName; | ||
this[Symbol.toStringTag] = id; | ||
this.__atom = new ReactAtom(id, this); | ||
this.__origRender = renderFunction || super.render; | ||
this.__lastError = undefined; | ||
if (renderError) { | ||
this.__lastData = undefined; | ||
this.__lastError = null; | ||
} | ||
class Cls extends (renderFunction | ||
? BaseComponent | ||
: OrigComponent) { | ||
constructor(props, context) { | ||
super(props, context); | ||
const id = (props && props.id) || | ||
this.constructor.displayName; | ||
this[Symbol.toStringTag] = id; | ||
this.__atom = new ReactAtom(id, this); | ||
this.__origRender = renderFunction || super.render; | ||
this.__lastError = undefined; | ||
if (renderError) { | ||
this.__lastData = undefined; | ||
this.__lastError = null; | ||
} | ||
__value() { | ||
return this.__origRender(this.props); | ||
} | ||
__value() { | ||
return this.__origRender(this.props); | ||
} | ||
componentDidCatch(error, init) { | ||
if (super.componentDidCatch) | ||
super.componentDidCatch(error, init); | ||
if (this.__lastError === undefined) | ||
return; | ||
this.__lastError = error; | ||
this.forceUpdate(); | ||
} | ||
componentWillUnmount() { | ||
if (super.componentWillUnmount) | ||
super.componentWillUnmount(); | ||
if (this.__atom === undefined) | ||
return; | ||
this.__atom.destructor(); | ||
this.__atom = undefined; | ||
} | ||
render() { | ||
if (this.__lastError === undefined) | ||
return this.__atom.render(); | ||
let data; | ||
try { | ||
if (this.__lastError) | ||
throw this.__lastError; | ||
data = this.__atom.render(); | ||
this.__lastData = data; | ||
} | ||
componentDidCatch(error, init) { | ||
if (super.componentDidCatch) | ||
super.componentDidCatch(error, init); | ||
if (this.__lastError === undefined) | ||
return; | ||
this.__lastError = error; | ||
this.forceUpdate(); | ||
catch (error) { | ||
this.__lastError = null; | ||
data = renderError({ | ||
ownerId: String(this.__atom), | ||
error, | ||
children: this.__lastData | ||
}); | ||
} | ||
componentDidUpdate(prevProps, prevState, snapshot) { | ||
if (super.componentDidUpdate) | ||
super.componentDidUpdate(prevProps, prevState, snapshot); | ||
this.__atom.reset(); | ||
} | ||
componentWillUnmount() { | ||
if (super.componentWillUnmount) | ||
super.componentWillUnmount(); | ||
if (this.__atom === undefined) | ||
return; | ||
this.__atom.destructor(); | ||
this.__atom = undefined; | ||
} | ||
render() { | ||
if (this.__lastError === undefined) | ||
return this.__atom.render(); | ||
let data; | ||
try { | ||
if (this.__lastError) | ||
throw this.__lastError; | ||
data = this.__atom.render(); | ||
this.__lastData = data; | ||
} | ||
catch (error) { | ||
this.__lastError = null; | ||
data = renderError({ | ||
ownerId: String(this.__atom), | ||
error, | ||
children: this.__lastData | ||
}); | ||
} | ||
return data; | ||
} | ||
}, | ||
_a.displayName = displayName, | ||
_a.__urc = true, | ||
_a); | ||
return data; | ||
} | ||
} | ||
Cls.displayName = displayName; | ||
Cls.__urc = true; | ||
__decorate([ | ||
reset_props | ||
], Cls.prototype, "props", void 0); | ||
__decorate([ | ||
reset_state | ||
], Cls.prototype, "state", void 0); | ||
if (renderFunction) { | ||
@@ -84,0 +133,0 @@ const props = Object.getOwnPropertyNames(OrigComponent); |
@@ -9,3 +9,2 @@ import { IRenderError, IReactAtomClass } from './interfaces'; | ||
state: State; | ||
componentDidUpdate?(prevProps: Readonly<Props>, prevState: Readonly<State>, snapshot?: any): void; | ||
forceUpdate(): void; | ||
@@ -12,0 +11,0 @@ componentDidCatch?(error: Error, errorInfo: ErrorInfo): void; |
{ | ||
"name": "urc", | ||
"version": "2.4.0", | ||
"version": "2.4.2", | ||
"license": "MIT", | ||
@@ -37,3 +37,3 @@ "description": "Universal react connect decorator builder", | ||
], | ||
"gitHead": "1c448814ec214c02229bcdec13021ebc6e17dd8d" | ||
"gitHead": "8155366f2fa337b0373b18f97e6ad628baba419d" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62444
376
1