Comparing version 2.4.2 to 2.4.3
@@ -6,2 +6,13 @@ # Change Log | ||
## [2.4.3](https://github.com/zerkalica/urc/compare/v2.4.2...v2.4.3) (2019-03-16) | ||
### Bug Fixes | ||
* shouldComponentUpdate, debug tags ([fa692e9](https://github.com/zerkalica/urc/commit/fa692e9)) | ||
## [2.4.2](https://github.com/zerkalica/urc/compare/v2.4.1...v2.4.2) (2019-03-13) | ||
@@ -8,0 +19,0 @@ |
@@ -5,24 +5,2 @@ '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) { | ||
@@ -32,30 +10,18 @@ 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; | ||
} | ||
}; | ||
const keyList = Object.keys; | ||
function shallowEqual(a, b) { | ||
if (a === b) | ||
return true; | ||
if (!(a instanceof Object) || !(b instanceof Object)) | ||
return false; | ||
const keys = keyList(a); | ||
const length = keys.length; | ||
for (let i = 0; i < length; i++) | ||
if (!(keys[i] in b)) | ||
return false; | ||
for (let i = 0; i < length; i++) | ||
if (a[keys[i]] !== b[keys[i]]) | ||
return false; | ||
return length === keyList(b).length; | ||
} | ||
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) { | ||
@@ -76,3 +42,4 @@ const renderFunction = isFunctionComponent(OrigComponent) | ||
this.__atom = new ReactAtom(id, this); | ||
this.__origRender = renderFunction || super.render; | ||
this.__origRender = | ||
renderFunction || super.render; | ||
this.__lastError = undefined; | ||
@@ -87,2 +54,10 @@ if (renderError) { | ||
} | ||
shouldComponentUpdate(nextProps, nextState) { | ||
const result = super.shouldComponentUpdate | ||
? super.shouldComponentUpdate(nextProps, nextState) | ||
: (shallowEqual(this.props, nextProps) || this.state !== nextState); | ||
if (result) | ||
this.__atom.reset(); | ||
return result; | ||
} | ||
componentDidCatch(error, init) { | ||
@@ -127,8 +102,2 @@ if (super.componentDidCatch) | ||
Cls.__urc = true; | ||
__decorate([ | ||
reset_props | ||
], Cls.prototype, "props", void 0); | ||
__decorate([ | ||
reset_state | ||
], Cls.prototype, "state", void 0); | ||
if (renderFunction) { | ||
@@ -135,0 +104,0 @@ const props = Object.getOwnPropertyNames(OrigComponent); |
@@ -9,2 +9,3 @@ import { IRenderError, IReactAtomClass } from './interfaces'; | ||
state: State; | ||
shouldComponentUpdate?(nextProps: Props, nextState: State, nextContext?: any): boolean; | ||
forceUpdate(): void; | ||
@@ -15,4 +16,4 @@ componentDidCatch?(error: Error, errorInfo: ErrorInfo): void; | ||
} | ||
export declare type ComponentDecorator<ReactNode> = (<Component extends ComponentClass<ReactNode>>(component: Component) => Component) | (<Component extends (<Props extends {}>(props?: Props) => ReactNode)>(component: Component) => Component); | ||
export declare type ComponentDecorator<ReactNode> = (<Component extends ComponentClass<ReactNode>>(component: Component) => Component) | (<Component extends <Props extends {}>(props?: Props) => ReactNode>(component: Component) => Component); | ||
export declare function createDecorator<ReactNode, Pure extends ComponentClass<ReactNode>>(ReactAtom: IReactAtomClass<ReactNode>, BaseComponent: Pure, renderError: IRenderError<ReactNode> | void): ComponentDecorator<ReactNode>; | ||
export {}; |
{ | ||
"name": "urc", | ||
"version": "2.4.2", | ||
"version": "2.4.3", | ||
"license": "MIT", | ||
@@ -37,3 +37,3 @@ "description": "Universal react connect decorator builder", | ||
], | ||
"gitHead": "8155366f2fa337b0373b18f97e6ad628baba419d" | ||
"gitHead": "41030711b0c631ea272c922ed1fa9f24a7238c34" | ||
} |
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
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
0
39289
323