[IMP] store: add 'deep' param to connect options

This commit is contained in:
Géry Debongnie
2019-04-15 11:44:03 +02:00
parent e005090296
commit 3d18359dd8
3 changed files with 60 additions and 3 deletions
+4 -2
View File
@@ -270,6 +270,8 @@ function deepRevNumber<T extends Object>(o: T): number {
export function connect(mapStateToProps, options: any = {}) {
let hashFunction = options.hashFunction || null;
let deep = "deep" in options ? options.deep : true;
let defaultRevFunction = deep ? deepRevNumber : revNumber;
return function(Comp) {
return class extends Comp {
@@ -283,7 +285,7 @@ export function connect(mapStateToProps, options: any = {}) {
this.__owl__.currentStoreProps = storeProps;
if (!hashFunction) {
if ("__owl__" in storeProps) {
hashFunction = s => deepRevNumber(s.storeProps);
hashFunction = s => defaultRevFunction(s.storeProps);
} else {
let areKeyObservable = false;
for (let key in storeProps) {
@@ -293,7 +295,7 @@ export function connect(mapStateToProps, options: any = {}) {
if (areKeyObservable) {
hashFunction = function({ storeProps }) {
return Object.values(storeProps).reduce(
(sum: number, val: any) => sum + deepRevNumber(val),
(sum: number, val: any) => sum + defaultRevFunction(val),
0
);
};