@xstate/store
Advanced tools
Comparing version 2.4.0 to 2.5.0
@@ -0,3 +1,4 @@ | ||
export { shallowEqual } from "./shallowEqual.js"; | ||
export { fromStore } from "./fromStore.js"; | ||
export { createStore, createStoreWithProducer } from "./store.js"; | ||
export * from "./types.js"; |
@@ -5,2 +5,26 @@ 'use strict'; | ||
// From https://github.com/reduxjs/react-redux/blob/720f0ba79236cdc3e1115f4ef9a7760a21784b48/src/utils/shallowEqual.ts | ||
function is(x, y) { | ||
if (x === y) { | ||
return x !== 0 || y !== 0 || 1 / x === 1 / y; | ||
} else { | ||
return x !== x && y !== y; | ||
} | ||
} | ||
function shallowEqual(objA, objB) { | ||
if (is(objA, objB)) return true; | ||
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) { | ||
return false; | ||
} | ||
const keysA = Object.keys(objA); | ||
const keysB = Object.keys(objB); | ||
if (keysA.length !== keysB.length) return false; | ||
for (let i = 0; i < keysA.length; i++) { | ||
if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
const symbolObservable = (() => typeof Symbol === 'function' && Symbol.observable || '@@observable')(); | ||
@@ -334,1 +358,2 @@ function toObserver(nextHandler, errorHandler, completionHandler) { | ||
exports.fromStore = fromStore; | ||
exports.shallowEqual = shallowEqual; |
@@ -0,1 +1,25 @@ | ||
// From https://github.com/reduxjs/react-redux/blob/720f0ba79236cdc3e1115f4ef9a7760a21784b48/src/utils/shallowEqual.ts | ||
function is(x, y) { | ||
if (x === y) { | ||
return x !== 0 || y !== 0 || 1 / x === 1 / y; | ||
} else { | ||
return x !== x && y !== y; | ||
} | ||
} | ||
function shallowEqual(objA, objB) { | ||
if (is(objA, objB)) return true; | ||
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) { | ||
return false; | ||
} | ||
const keysA = Object.keys(objA); | ||
const keysB = Object.keys(objB); | ||
if (keysA.length !== keysB.length) return false; | ||
for (let i = 0; i < keysA.length; i++) { | ||
if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
const symbolObservable = (() => typeof Symbol === 'function' && Symbol.observable || '@@observable')(); | ||
@@ -326,2 +350,2 @@ function toObserver(nextHandler, errorHandler, completionHandler) { | ||
export { createStore, createStoreWithProducer, fromStore }; | ||
export { createStore, createStoreWithProducer, fromStore, shallowEqual }; |
{ | ||
"name": "@xstate/store", | ||
"version": "2.4.0", | ||
"version": "2.5.0", | ||
"description": "Simple stores", | ||
@@ -66,4 +66,4 @@ "keywords": [ | ||
"solid-testing-library": "^0.3.0", | ||
"@xstate/vue": "^3.1.3", | ||
"@xstate/react": "^4.1.2", | ||
"@xstate/vue": "^3.1.3", | ||
"xstate": "^5.18.1" | ||
@@ -70,0 +70,0 @@ }, |
Sorry, the diff of this file is not supported yet
54729
27
1357