Socket
Socket
Sign inDemoInstall

boxes

Package Overview
Dependencies
1
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.39.0 to 0.40.0

10

lib/boxes.js

@@ -18,3 +18,5 @@ "use strict";

link[prop] = newValue;
ee_1.default.emit(proxy, prop, proxy, prop, 'set', oldValue, newValue);
if (target.__isWatched) {
ee_1.default.emit(proxy, prop, proxy, prop, 'set', oldValue, newValue);
}
return true;

@@ -34,2 +36,3 @@ }

const target = isArray ? [] : {};
tools_1.setHiddenKey(target, '__isWatched', false);
tools_1.setHiddenKey(target, '__isBox', true);

@@ -49,3 +52,5 @@ Object.keys(origin).forEach(key => {

delete target[prop];
ee_1.default.emit(proxy, prop, proxy, prop, 'delete', oldValue, undefined);
if (target.__isWatched) {
ee_1.default.emit(proxy, prop, proxy, prop, 'delete', oldValue, undefined);
}
return true;

@@ -85,2 +90,3 @@ }

const prevValue = prevScope[currentProp];
nextScope.__isWatched = true;
nextController.transfer(nextScope);

@@ -87,0 +93,0 @@ nextValue !== prevValue &&

8

lib/ee.d.ts

@@ -1,2 +0,8 @@

declare const ee: import("weak-emitter").WeakEventEmitter;
import { Box } from './tools';
declare type EventHandler = (...args: any[]) => void;
declare const ee: {
emit: (context: object, key: string | number | symbol | object, ...args: any[]) => void;
off: (context: object, key: string | number | symbol | object, handler: (...args: any[]) => void) => void;
on: (box: Box, prop: string, handler: EventHandler) => import("weak-emitter").WeakEventController;
};
export default ee;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const weak_emitter_1 = require("weak-emitter");
const ee = weak_emitter_1.weakEmitter();
const emitter = weak_emitter_1.weakEmitter();
const ee = {
emit: emitter.emit,
off: emitter.off,
on: (box, prop, handler) => {
box.__isWatched = true;
return emitter.on(box, prop, handler);
}
};
exports.default = ee;

@@ -10,2 +10,6 @@ "use strict";

return function (targ, start = 0, end = target.length) {
if (!target.__isWatched) {
target.copyWithin(targ, start, end);
return proxy;
}
const len = target.length;

@@ -38,2 +42,7 @@ if (targ < 0)

return function (value, start = 0, end = target.length) {
if (!target.__isWatched) {
const fill = getBox(value);
target.fill(fill, start, end);
return proxy;
}
value = getBox(value);

@@ -65,2 +74,4 @@ const len = target.length;

pop: (target, proxy) => () => {
if (!target.__isWatched)
return target.pop();
const result = target.pop();

@@ -74,2 +85,7 @@ const len = target.length;

push: (target, proxy, getBox) => function (...args) {
if (!target.__isWatched) {
const items = args.map(val => getBox(val));
target.push(...items);
return target.length;
}
args.forEach((value) => {

@@ -87,2 +103,6 @@ const len = target.length;

reverse: (target, proxy) => () => {
if (!target.__isWatched) {
target.reverse();
return proxy;
}
const len = target.length;

@@ -106,2 +126,4 @@ target.reverse();

shift: (target, proxy) => () => {
if (!target.__isWatched)
return target.shift();
const shifted = target.shift();

@@ -115,3 +137,7 @@ ee_1.default.emit(proxy, '0', proxy, '0', 'remove', shifted, undefined);

return function (fn) {
const copy = [...target];
if (!target.__isWatched) {
target.sort(fn);
return proxy;
}
const copy = target.slice();
target.sort(fn);

@@ -130,2 +156,10 @@ target.forEach((item, i) => {

return function (start, deleteCount, ...entries) {
if (!target.__isWatched) {
const items = entries ? getBox(entries) : [];
if (!('0' in arguments))
return [];
return '1' in arguments
? target.splice(start, deleteCount, ...items)
: target.splice(start);
}
const initLen = target.length;

@@ -170,3 +204,8 @@ const items = getBox(entries || []);

},
unshift: (target, proxy, getBox) => function () {
unshift: (target, proxy, getBox) => function (...args) {
if (!target.__isWatched) {
const items = getBox(args || []);
target.unshift(...items);
return target.length;
}
const firstIndexChanged = arguments.length;

@@ -173,0 +212,0 @@ let i = firstIndexChanged;

@@ -6,6 +6,8 @@ export declare type Prox = {

__isBox: true;
__isWatched: boolean;
[index: string]: any;
}
export declare type ArrayBox = any[] & Box;
export declare function setHiddenKey(target: Prox, key: string, value: any): asserts target is Box;
export declare function isObject(target: Prox): boolean;
export declare function isBox(target: any): boolean;

@@ -7,3 +7,4 @@ "use strict";

enumerable: false,
configurable: true
configurable: true,
writable: true
});

@@ -10,0 +11,0 @@ }

{
"name": "boxes",
"version": "0.39.0",
"version": "0.40.0",
"description": "Reactive state containers for js apps",

@@ -5,0 +5,0 @@ "type": "module",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc