mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] store: properly compare values on store updates
Before this commit, we tried to use a hash function for non observable values, but this was not correct, since some changes could be done that would compensate each other. With this commit, we properly compare each non observable value.
This commit is contained in:
+34
-20
@@ -273,17 +273,22 @@ export function connect(mapStateToProps, options: any = {}) {
|
|||||||
if (!hashFunction) {
|
if (!hashFunction) {
|
||||||
let deep = "deep" in options ? options.deep : true;
|
let deep = "deep" in options ? options.deep : true;
|
||||||
let defaultRevFunction = deep ? deepRevNumber : revNumber;
|
let defaultRevFunction = deep ? deepRevNumber : revNumber;
|
||||||
hashFunction = function({ storeProps, currentStoreProps }) {
|
hashFunction = function({ storeProps }, options) {
|
||||||
|
const { currentStoreProps } = options;
|
||||||
if ("__owl__" in storeProps) {
|
if ("__owl__" in storeProps) {
|
||||||
return defaultRevFunction(storeProps);
|
return defaultRevFunction(storeProps);
|
||||||
}
|
}
|
||||||
let hash = 0;
|
let hash = 0;
|
||||||
let currentProps = currentStoreProps;
|
|
||||||
for (let key in storeProps) {
|
for (let key in storeProps) {
|
||||||
const val = storeProps[key];
|
const val = storeProps[key];
|
||||||
hash +=
|
const hashVal = defaultRevFunction(val);
|
||||||
defaultRevFunction(storeProps[key]) ||
|
if (hashVal === 0) {
|
||||||
(val !== currentProps[key] ? 1 : 0);
|
if (val !== currentStoreProps[key]) {
|
||||||
|
options.didChange = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
hash += hashVal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return hash;
|
return hash;
|
||||||
};
|
};
|
||||||
@@ -299,26 +304,35 @@ export function connect(mapStateToProps, options: any = {}) {
|
|||||||
super(parent, mergedProps);
|
super(parent, mergedProps);
|
||||||
this.__owl__.ownProps = ownProps;
|
this.__owl__.ownProps = ownProps;
|
||||||
this.__owl__.currentStoreProps = storeProps;
|
this.__owl__.currentStoreProps = storeProps;
|
||||||
this.__owl__.storeHash = hashFunction({
|
this.__owl__.storeHash = hashFunction(
|
||||||
state: env.store.state,
|
{
|
||||||
storeProps: storeProps,
|
state: env.store.state,
|
||||||
currentStoreProps: storeProps,
|
storeProps: storeProps,
|
||||||
revNumber,
|
revNumber,
|
||||||
deepRevNumber
|
deepRevNumber
|
||||||
});
|
},
|
||||||
|
{
|
||||||
|
currentStoreProps: storeProps
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
mounted() {
|
mounted() {
|
||||||
this.env.store.on("update", this, () => {
|
this.env.store.on("update", this, () => {
|
||||||
const ownProps = this.__owl__.ownProps;
|
const ownProps = this.__owl__.ownProps;
|
||||||
const storeProps = mapStateToProps(this.env.store.state, ownProps);
|
const storeProps = mapStateToProps(this.env.store.state, ownProps);
|
||||||
let didChange = false;
|
const options: any = {
|
||||||
const storeHash = hashFunction({
|
currentStoreProps: this.__owl__.currentStoreProps
|
||||||
state: this.env.store.state,
|
};
|
||||||
storeProps: storeProps,
|
const storeHash = hashFunction(
|
||||||
currentStoreProps: this.__owl__.currentStoreProps,
|
{
|
||||||
revNumber,
|
state: this.env.store.state,
|
||||||
deepRevNumber
|
storeProps: storeProps,
|
||||||
});
|
revNumber,
|
||||||
|
deepRevNumber
|
||||||
|
},
|
||||||
|
options
|
||||||
|
);
|
||||||
|
let didChange = options.didChange;
|
||||||
if (storeHash !== this.__owl__.storeHash) {
|
if (storeHash !== this.__owl__.storeHash) {
|
||||||
didChange = true;
|
didChange = true;
|
||||||
this.__owl__.storeHash = storeHash;
|
this.__owl__.storeHash = storeHash;
|
||||||
|
|||||||
Reference in New Issue
Block a user