[IMP] store: connect function takes hash function in param

With this commit, we can now decides precisely if a component should be
rerendered, by using a hash function.

By default, the hash function will deep observe each store element
coming from the result of the mapStateToProps.

closes #24
This commit is contained in:
Géry Debongnie
2019-04-14 21:37:05 +02:00
parent f5bbf25d4f
commit 7b87470760
5 changed files with 85 additions and 29 deletions
+12
View File
@@ -5,6 +5,7 @@ import {
memoize,
debounce,
findInTree,
shallowEqual,
patch,
unpatch
} from "../src/utils";
@@ -94,6 +95,17 @@ describe("findInTree", () => {
});
});
describe("shallowEqual", () => {
test("simple comparisons", () => {
const obj1 = {};
expect(shallowEqual(obj1, obj1)).toBe(true);
expect(shallowEqual({}, {})).toBe(true);
expect(shallowEqual({ a: 1 }, {})).toBe(false);
expect(shallowEqual({ a: 1 }, { a: 1 })).toBe(true);
expect(shallowEqual({ a: 1 }, ["a"])).toBe(false);
});
});
describe("patch/unpatch", () => {
test("can monkey patch a class", () => {
class Test {