react-reducer-store
Advanced tools
Comparing version
@@ -24,24 +24,2 @@ 'use strict'; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function _slicedToArray(arr, i) { | ||
@@ -85,41 +63,24 @@ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); | ||
var StoreSubscribers = | ||
/*#__PURE__*/ | ||
function () { | ||
function StoreSubscribers() { | ||
_classCallCheck(this, StoreSubscribers); | ||
var subscribers = []; | ||
this.subscribers = []; | ||
function subscribe(fn) { | ||
if (typeof fn === 'function' && subscribers.indexOf(fn) === -1) { | ||
subscribers.push(fn); | ||
} | ||
} | ||
_createClass(StoreSubscribers, [{ | ||
key: "subscribe", | ||
value: function subscribe(fn) { | ||
if (typeof fn === 'function' && this.subscribers.indexOf(fn) === -1) { | ||
this.subscribers.push(fn); | ||
} | ||
} | ||
}, { | ||
key: "unsubscribe", | ||
value: function unsubscribe(fn) { | ||
var index = this.subscribers.indexOf(fn); | ||
function unsubscribe(fn) { | ||
var index = subscribers.indexOf(fn); | ||
if (index !== -1) { | ||
this.subscribers.splice(index, 1); | ||
} | ||
} | ||
}, { | ||
key: "publish", | ||
value: function publish(state) { | ||
this.subscribers.forEach(function (fn) { | ||
return fn(state); | ||
}); | ||
} | ||
}]); | ||
if (index !== -1) { | ||
subscribers.splice(index, 1); | ||
} | ||
} | ||
return StoreSubscribers; | ||
}(); | ||
function publish(state) { | ||
subscribers.forEach(function (fn) { | ||
return fn(state); | ||
}); | ||
} | ||
var StoreSubscribers$1 = new StoreSubscribers(); | ||
var DispatchContext = React.createContext(); | ||
@@ -149,3 +110,3 @@ | ||
StoreSubscribers$1.publish(state); | ||
publish(state); | ||
}, [state]); | ||
@@ -196,5 +157,5 @@ globalDispatch = dispatch; | ||
React.useEffect(function () { | ||
StoreSubscribers$1.subscribe(handleContextChange); | ||
subscribe(handleContextChange); | ||
return function () { | ||
return StoreSubscribers$1.unsubscribe(handleContextChange); | ||
return unsubscribe(handleContextChange); | ||
}; | ||
@@ -201,0 +162,0 @@ }, []); |
@@ -17,24 +17,2 @@ import React, { createContext, useReducer, useEffect, useState, useContext } from 'react'; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function _slicedToArray(arr, i) { | ||
@@ -78,41 +56,24 @@ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); | ||
var StoreSubscribers = | ||
/*#__PURE__*/ | ||
function () { | ||
function StoreSubscribers() { | ||
_classCallCheck(this, StoreSubscribers); | ||
var subscribers = []; | ||
this.subscribers = []; | ||
function subscribe(fn) { | ||
if (typeof fn === 'function' && subscribers.indexOf(fn) === -1) { | ||
subscribers.push(fn); | ||
} | ||
} | ||
_createClass(StoreSubscribers, [{ | ||
key: "subscribe", | ||
value: function subscribe(fn) { | ||
if (typeof fn === 'function' && this.subscribers.indexOf(fn) === -1) { | ||
this.subscribers.push(fn); | ||
} | ||
} | ||
}, { | ||
key: "unsubscribe", | ||
value: function unsubscribe(fn) { | ||
var index = this.subscribers.indexOf(fn); | ||
function unsubscribe(fn) { | ||
var index = subscribers.indexOf(fn); | ||
if (index !== -1) { | ||
this.subscribers.splice(index, 1); | ||
} | ||
} | ||
}, { | ||
key: "publish", | ||
value: function publish(state) { | ||
this.subscribers.forEach(function (fn) { | ||
return fn(state); | ||
}); | ||
} | ||
}]); | ||
if (index !== -1) { | ||
subscribers.splice(index, 1); | ||
} | ||
} | ||
return StoreSubscribers; | ||
}(); | ||
function publish(state) { | ||
subscribers.forEach(function (fn) { | ||
return fn(state); | ||
}); | ||
} | ||
var StoreSubscribers$1 = new StoreSubscribers(); | ||
var DispatchContext = createContext(); | ||
@@ -142,3 +103,3 @@ | ||
StoreSubscribers$1.publish(state); | ||
publish(state); | ||
}, [state]); | ||
@@ -189,5 +150,5 @@ globalDispatch = dispatch; | ||
useEffect(function () { | ||
StoreSubscribers$1.subscribe(handleContextChange); | ||
subscribe(handleContextChange); | ||
return function () { | ||
return StoreSubscribers$1.unsubscribe(handleContextChange); | ||
return unsubscribe(handleContextChange); | ||
}; | ||
@@ -194,0 +155,0 @@ }, []); |
{ | ||
"name": "react-reducer-store", | ||
"version": "2.1.2", | ||
"version": "2.1.3", | ||
"main": "dist/index.cjs.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/index.esm.js", |
47235
-4.98%303
-18.77%