You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@aha-app/react-easy-state

Package Overview
Dependencies
Maintainers
40
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aha-app/react-easy-state - npm Package Compare versions

Comparing version

to
0.0.11-development

241

dist/cjs.es5.js

@@ -9,2 +9,28 @@ 'use strict';

function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
enumerableOnly && (symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
})), keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = null != arguments[i] ? arguments[i] : {};
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
_defineProperty(target, key, source[key]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
function _classCallCheck(instance, Constructor) {

@@ -29,2 +55,5 @@ if (!(instance instanceof Constructor)) {

if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;

@@ -48,36 +77,2 @@ }

function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys(Object(source), true).forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
}
return target;
}
function _inherits(subClass, superClass) {

@@ -95,2 +90,5 @@ if (typeof superClass !== "function" && superClass !== null) {

});
Object.defineProperty(subClass, "prototype", {
writable: false
});
if (superClass) _setPrototypeOf(subClass, superClass);

@@ -115,2 +113,15 @@ }

function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _assertThisInitialized(self) {

@@ -127,2 +138,4 @@ if (self === void 0) {

return call;
} else if (call !== void 0) {
throw new TypeError("Derived constructors may only return object or undefined");
}

@@ -133,2 +146,21 @@

function _createSuper(Derived) {
var hasNativeReflectConstruct = _isNativeReflectConstruct();
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result;
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
function _superPropBase(object, property) {

@@ -143,3 +175,3 @@ while (!Object.prototype.hasOwnProperty.call(object, property)) {

function _get(target, property, receiver) {
function _get() {
if (typeof Reflect !== "undefined" && Reflect.get) {

@@ -155,3 +187,3 @@ _get = Reflect.get;

if (desc.get) {
return desc.get.call(receiver);
return desc.get.call(arguments.length < 3 ? target : receiver);
}

@@ -163,19 +195,15 @@

return _get(target, property, receiver || target);
return _get.apply(this, arguments);
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
return arr2;
}
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}

@@ -188,17 +216,17 @@

function _iterableToArray(iter) {
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _iterableToArrayLimit(arr, i) {
if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
return;
}
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
var _s, _e;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);

@@ -222,10 +250,32 @@

function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance");
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
// it is window in the DOM and global in NodeJS and React Native
var isDOM = typeof window !== 'undefined';
var isNative = typeof global !== 'undefined';
var globalObj = isDOM ? window : isNative ? global : undefined;
var hasHooks = typeof react.useState === 'function';

@@ -250,2 +300,5 @@

// in a setTimeout callback, in an event handler.
//
// NOTE: This should be revisited after React improves batching for
// Suspense / etc.

@@ -256,4 +309,15 @@

var viewIndexCounter = 0;
var inEventLoop = false;
function batchSetState(viewIndex, fn) {
if (inEventLoop) {
// If we are in the main event loop, React handles the batching
// automatically, so we run the change immediately. Deferring the
// update can cause unexpected cursor shifts in input elements,
// since the change can't be tied back to the action:
// https://github.com/facebook/react/issues/5386
fn();
return;
}
batchesPending[viewIndex] = fn;

@@ -279,4 +343,65 @@

delete batchesPending[viewIndex];
} // this creates and returns a wrapped version of the passed function
// the cache is necessary to always map the same thing to the same function
// which makes sure that addEventListener/removeEventListener pairs don't break
var cache = new WeakMap();
function wrapFn(fn, wrapper) {
if (typeof fn !== 'function') {
return fn;
}
var wrapped = cache.get(fn);
if (!wrapped) {
wrapped = function wrapped() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return wrapper(fn, this, args);
};
cache.set(fn, wrapped);
}
return wrapped;
}
function wrapMethodCallbacks(obj, method, wrapper) {
var descriptor = Object.getOwnPropertyDescriptor(obj, method);
if (descriptor && descriptor.writable && typeof descriptor.value === 'function') {
obj[method] = new Proxy(descriptor.value, {
apply: function apply(target, ctx, args) {
return Reflect.apply(target, ctx, args.map(function (f) {
return wrapFn(f, wrapper);
}));
}
});
}
} // wrapped obj.addEventListener(cb) like callbacks
function wrapMethodsCallbacks(obj, methods, wrapper) {
methods.forEach(function (method) {
return wrapMethodCallbacks(obj, method, wrapper);
});
} // batch addEventListener calls
if (globalObj.EventTarget) {
wrapMethodsCallbacks(EventTarget.prototype, ['addEventListener', 'removeEventListener'], function (fn, ctx, args) {
inEventLoop = true;
try {
fn.apply(ctx, args);
} finally {
inEventLoop = false;
}
});
}
function view(Comp) {

@@ -337,2 +462,4 @@ var isStatelessComp = !(Comp.prototype && Comp.prototype.isReactComponent);

var _super = _createSuper(ReactiveClassComp);
function ReactiveClassComp(props, context) {

@@ -343,3 +470,3 @@ var _this;

_this = _possibleConstructorReturn(this, _getPrototypeOf(ReactiveClassComp).call(this, props, context)); // Unique ID for each class insance.
_this = _super.call(this, props, context); // Unique ID for each class insance.

@@ -501,3 +628,3 @@ viewIndexCounter += 1;

var cache = new WeakMap();
var cache$1 = new WeakMap();

@@ -509,3 +636,3 @@ function batchFn(fn) {

var batched = cache.get(fn);
var batched = cache$1.get(fn);

@@ -518,3 +645,3 @@ if (!batched) {

});
cache.set(fn, batched);
cache$1.set(fn, batched);
}

@@ -538,3 +665,3 @@

if (configurable && typeof set === 'function') {
Object.defineProperty(obj, method, _objectSpread2({}, descriptor, {
Object.defineProperty(obj, method, _objectSpread2(_objectSpread2({}, descriptor), {}, {
set: batchFn(set)

@@ -541,0 +668,0 @@ }));

@@ -9,2 +9,7 @@ 'use strict';

// it is window in the DOM and global in NodeJS and React Native
const isDOM = typeof window !== 'undefined';
const isNative = typeof global !== 'undefined';
const globalObj = isDOM ? window : isNative ? global : undefined;
const hasHooks = typeof react.useState === 'function';

@@ -28,2 +33,5 @@

// in a setTimeout callback, in an event handler.
//
// NOTE: This should be revisited after React improves batching for
// Suspense / etc.

@@ -34,4 +42,15 @@

let viewIndexCounter = 0;
let inEventLoop = false;
function batchSetState(viewIndex, fn) {
if (inEventLoop) {
// If we are in the main event loop, React handles the batching
// automatically, so we run the change immediately. Deferring the
// update can cause unexpected cursor shifts in input elements,
// since the change can't be tied back to the action:
// https://github.com/facebook/react/issues/5386
fn();
return;
}
batchesPending[viewIndex] = fn;

@@ -53,4 +72,58 @@

delete batchesPending[viewIndex];
} // this creates and returns a wrapped version of the passed function
// the cache is necessary to always map the same thing to the same function
// which makes sure that addEventListener/removeEventListener pairs don't break
const cache = new WeakMap();
function wrapFn(fn, wrapper) {
if (typeof fn !== 'function') {
return fn;
}
let wrapped = cache.get(fn);
if (!wrapped) {
wrapped = function (...args) {
return wrapper(fn, this, args);
};
cache.set(fn, wrapped);
}
return wrapped;
}
function wrapMethodCallbacks(obj, method, wrapper) {
const descriptor = Object.getOwnPropertyDescriptor(obj, method);
if (descriptor && descriptor.writable && typeof descriptor.value === 'function') {
obj[method] = new Proxy(descriptor.value, {
apply(target, ctx, args) {
return Reflect.apply(target, ctx, args.map(f => wrapFn(f, wrapper)));
}
});
}
} // wrapped obj.addEventListener(cb) like callbacks
function wrapMethodsCallbacks(obj, methods, wrapper) {
methods.forEach(method => wrapMethodCallbacks(obj, method, wrapper));
} // batch addEventListener calls
if (globalObj.EventTarget) {
wrapMethodsCallbacks(EventTarget.prototype, ['addEventListener', 'removeEventListener'], (fn, ctx, args) => {
inEventLoop = true;
try {
fn.apply(ctx, args);
} finally {
inEventLoop = false;
}
});
}
function view(Comp) {

@@ -195,17 +268,2 @@ const isStatelessComp = !(Comp.prototype && Comp.prototype.isReactComponent);

function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function ownKeys(object, enumerableOnly) {

@@ -216,6 +274,5 @@ var keys = Object.keys(object);

var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) symbols = symbols.filter(function (sym) {
enumerableOnly && (symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
keys.push.apply(keys, symbols);
})), keys.push.apply(keys, symbols);
}

@@ -228,15 +285,8 @@

for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys(Object(source), true).forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
var source = null != arguments[i] ? arguments[i] : {};
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
_defineProperty(target, key, source[key]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}

@@ -247,2 +297,17 @@

function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
const taskQueue = new Set();

@@ -297,3 +362,3 @@ const scheduler = {

const cache = new WeakMap();
const cache$1 = new WeakMap();

@@ -305,3 +370,3 @@ function batchFn(fn) {

let batched = cache.get(fn);
let batched = cache$1.get(fn);

@@ -315,3 +380,3 @@ if (!batched) {

});
cache.set(fn, batched);
cache$1.set(fn, batched);
}

@@ -337,3 +402,3 @@

if (configurable && typeof set === 'function') {
Object.defineProperty(obj, method, _objectSpread2({}, descriptor, {
Object.defineProperty(obj, method, _objectSpread2(_objectSpread2({}, descriptor), {}, {
set: batchFn(set)

@@ -340,0 +405,0 @@ }));

@@ -6,2 +6,28 @@ import { useState, memo, useMemo, useEffect, Component } from 'react';

function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
enumerableOnly && (symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
})), keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = null != arguments[i] ? arguments[i] : {};
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
_defineProperty(target, key, source[key]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
function _classCallCheck(instance, Constructor) {

@@ -26,2 +52,5 @@ if (!(instance instanceof Constructor)) {

if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;

@@ -45,36 +74,2 @@ }

function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys(Object(source), true).forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
}
return target;
}
function _inherits(subClass, superClass) {

@@ -92,2 +87,5 @@ if (typeof superClass !== "function" && superClass !== null) {

});
Object.defineProperty(subClass, "prototype", {
writable: false
});
if (superClass) _setPrototypeOf(subClass, superClass);

@@ -112,2 +110,15 @@ }

function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _assertThisInitialized(self) {

@@ -124,2 +135,4 @@ if (self === void 0) {

return call;
} else if (call !== void 0) {
throw new TypeError("Derived constructors may only return object or undefined");
}

@@ -130,2 +143,21 @@

function _createSuper(Derived) {
var hasNativeReflectConstruct = _isNativeReflectConstruct();
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result;
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
function _superPropBase(object, property) {

@@ -140,3 +172,3 @@ while (!Object.prototype.hasOwnProperty.call(object, property)) {

function _get(target, property, receiver) {
function _get() {
if (typeof Reflect !== "undefined" && Reflect.get) {

@@ -152,3 +184,3 @@ _get = Reflect.get;

if (desc.get) {
return desc.get.call(receiver);
return desc.get.call(arguments.length < 3 ? target : receiver);
}

@@ -160,19 +192,15 @@

return _get(target, property, receiver || target);
return _get.apply(this, arguments);
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
return arr2;
}
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}

@@ -185,17 +213,17 @@

function _iterableToArray(iter) {
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _iterableToArrayLimit(arr, i) {
if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
return;
}
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
var _s, _e;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);

@@ -219,10 +247,32 @@

function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance");
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
// it is window in the DOM and global in NodeJS and React Native
var isDOM = typeof window !== 'undefined';
var isNative = typeof global !== 'undefined';
var globalObj = isDOM ? window : isNative ? global : undefined;
var hasHooks = typeof useState === 'function';

@@ -247,2 +297,5 @@

// in a setTimeout callback, in an event handler.
//
// NOTE: This should be revisited after React improves batching for
// Suspense / etc.

@@ -253,4 +306,15 @@

var viewIndexCounter = 0;
var inEventLoop = false;
function batchSetState(viewIndex, fn) {
if (inEventLoop) {
// If we are in the main event loop, React handles the batching
// automatically, so we run the change immediately. Deferring the
// update can cause unexpected cursor shifts in input elements,
// since the change can't be tied back to the action:
// https://github.com/facebook/react/issues/5386
fn();
return;
}
batchesPending[viewIndex] = fn;

@@ -276,4 +340,65 @@

delete batchesPending[viewIndex];
} // this creates and returns a wrapped version of the passed function
// the cache is necessary to always map the same thing to the same function
// which makes sure that addEventListener/removeEventListener pairs don't break
var cache = new WeakMap();
function wrapFn(fn, wrapper) {
if (typeof fn !== 'function') {
return fn;
}
var wrapped = cache.get(fn);
if (!wrapped) {
wrapped = function wrapped() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return wrapper(fn, this, args);
};
cache.set(fn, wrapped);
}
return wrapped;
}
function wrapMethodCallbacks(obj, method, wrapper) {
var descriptor = Object.getOwnPropertyDescriptor(obj, method);
if (descriptor && descriptor.writable && typeof descriptor.value === 'function') {
obj[method] = new Proxy(descriptor.value, {
apply: function apply(target, ctx, args) {
return Reflect.apply(target, ctx, args.map(function (f) {
return wrapFn(f, wrapper);
}));
}
});
}
} // wrapped obj.addEventListener(cb) like callbacks
function wrapMethodsCallbacks(obj, methods, wrapper) {
methods.forEach(function (method) {
return wrapMethodCallbacks(obj, method, wrapper);
});
} // batch addEventListener calls
if (globalObj.EventTarget) {
wrapMethodsCallbacks(EventTarget.prototype, ['addEventListener', 'removeEventListener'], function (fn, ctx, args) {
inEventLoop = true;
try {
fn.apply(ctx, args);
} finally {
inEventLoop = false;
}
});
}
function view(Comp) {

@@ -334,2 +459,4 @@ var isStatelessComp = !(Comp.prototype && Comp.prototype.isReactComponent);

var _super = _createSuper(ReactiveClassComp);
function ReactiveClassComp(props, context) {

@@ -340,3 +467,3 @@ var _this;

_this = _possibleConstructorReturn(this, _getPrototypeOf(ReactiveClassComp).call(this, props, context)); // Unique ID for each class insance.
_this = _super.call(this, props, context); // Unique ID for each class insance.

@@ -498,3 +625,3 @@ viewIndexCounter += 1;

var cache = new WeakMap();
var cache$1 = new WeakMap();

@@ -506,3 +633,3 @@ function batchFn(fn) {

var batched = cache.get(fn);
var batched = cache$1.get(fn);

@@ -515,3 +642,3 @@ if (!batched) {

});
cache.set(fn, batched);
cache$1.set(fn, batched);
}

@@ -535,3 +662,3 @@

if (configurable && typeof set === 'function') {
Object.defineProperty(obj, method, _objectSpread2({}, descriptor, {
Object.defineProperty(obj, method, _objectSpread2(_objectSpread2({}, descriptor), {}, {
set: batchFn(set)

@@ -538,0 +665,0 @@ }));

@@ -6,2 +6,7 @@ import { useState, memo, useMemo, useEffect, Component } from 'react';

// it is window in the DOM and global in NodeJS and React Native
const isDOM = typeof window !== 'undefined';
const isNative = typeof global !== 'undefined';
const globalObj = isDOM ? window : isNative ? global : undefined;
const hasHooks = typeof useState === 'function';

@@ -25,2 +30,5 @@

// in a setTimeout callback, in an event handler.
//
// NOTE: This should be revisited after React improves batching for
// Suspense / etc.

@@ -31,4 +39,15 @@

let viewIndexCounter = 0;
let inEventLoop = false;
function batchSetState(viewIndex, fn) {
if (inEventLoop) {
// If we are in the main event loop, React handles the batching
// automatically, so we run the change immediately. Deferring the
// update can cause unexpected cursor shifts in input elements,
// since the change can't be tied back to the action:
// https://github.com/facebook/react/issues/5386
fn();
return;
}
batchesPending[viewIndex] = fn;

@@ -50,4 +69,58 @@

delete batchesPending[viewIndex];
} // this creates and returns a wrapped version of the passed function
// the cache is necessary to always map the same thing to the same function
// which makes sure that addEventListener/removeEventListener pairs don't break
const cache = new WeakMap();
function wrapFn(fn, wrapper) {
if (typeof fn !== 'function') {
return fn;
}
let wrapped = cache.get(fn);
if (!wrapped) {
wrapped = function (...args) {
return wrapper(fn, this, args);
};
cache.set(fn, wrapped);
}
return wrapped;
}
function wrapMethodCallbacks(obj, method, wrapper) {
const descriptor = Object.getOwnPropertyDescriptor(obj, method);
if (descriptor && descriptor.writable && typeof descriptor.value === 'function') {
obj[method] = new Proxy(descriptor.value, {
apply(target, ctx, args) {
return Reflect.apply(target, ctx, args.map(f => wrapFn(f, wrapper)));
}
});
}
} // wrapped obj.addEventListener(cb) like callbacks
function wrapMethodsCallbacks(obj, methods, wrapper) {
methods.forEach(method => wrapMethodCallbacks(obj, method, wrapper));
} // batch addEventListener calls
if (globalObj.EventTarget) {
wrapMethodsCallbacks(EventTarget.prototype, ['addEventListener', 'removeEventListener'], (fn, ctx, args) => {
inEventLoop = true;
try {
fn.apply(ctx, args);
} finally {
inEventLoop = false;
}
});
}
function view(Comp) {

@@ -192,17 +265,2 @@ const isStatelessComp = !(Comp.prototype && Comp.prototype.isReactComponent);

function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function ownKeys(object, enumerableOnly) {

@@ -213,6 +271,5 @@ var keys = Object.keys(object);

var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) symbols = symbols.filter(function (sym) {
enumerableOnly && (symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
keys.push.apply(keys, symbols);
})), keys.push.apply(keys, symbols);
}

@@ -225,15 +282,8 @@

for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys(Object(source), true).forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
var source = null != arguments[i] ? arguments[i] : {};
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
_defineProperty(target, key, source[key]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}

@@ -244,2 +294,17 @@

function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
const taskQueue = new Set();

@@ -294,3 +359,3 @@ const scheduler = {

const cache = new WeakMap();
const cache$1 = new WeakMap();

@@ -302,3 +367,3 @@ function batchFn(fn) {

let batched = cache.get(fn);
let batched = cache$1.get(fn);

@@ -312,3 +377,3 @@ if (!batched) {

});
cache.set(fn, batched);
cache$1.set(fn, batched);
}

@@ -334,3 +399,3 @@

if (configurable && typeof set === 'function') {
Object.defineProperty(obj, method, _objectSpread2({}, descriptor, {
Object.defineProperty(obj, method, _objectSpread2(_objectSpread2({}, descriptor), {}, {
set: batchFn(set)

@@ -337,0 +402,0 @@ }));

{
"name": "@aha-app/react-easy-state",
"version": "0.0.10-development",
"version": "0.0.11-development",
"description": "React state management with a minimal API. Made with ES6 Proxies.",

@@ -62,3 +62,3 @@ "main": "dist/cjs.es6.js",

"dependencies": {
"@nx-js/observer-util": "^4.3.0-alpha.2"
"@nx-js/observer-util": "^4.2.2"
},

@@ -76,3 +76,3 @@ "peerDependencies": {

"@babel/polyfill": "^7.8.7",
"@babel/preset-env": "^7.8.7",
"@babel/preset-env": "^7.9.0",
"@babel/preset-react": "^7.8.3",

@@ -79,0 +79,0 @@ "@commitlint/cli": "^8.3.5",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet