Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

boxed-immutable

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

boxed-immutable - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

23

index.js
'use strict';
const boxed = require('./lib/boxed-immutable');
const boxedOnDemand = require('./lib/boxed-on-demand');
const onDemand = require('./lib/boxed-on-demand');
const util = require('./lib/util');
exports._$ = boxed.box;
exports.createBox = boxed.createBox;
exports.boxedOnDemand = boxedOnDemand.boxedOnDemand;
boxed.BoxedOnDemand = onDemand.BoxedOnDemand;
boxed.boxOnDemand = onDemand.boxOnDemand;
// mostly for testing
exports.Boxed = boxed.Boxed;
exports.BoxedOnDemand = boxedOnDemand.BoxedOnDemand;
exports.BOXED_GET_THIS = boxed.BOXED_GET_THIS;
module.exports = {
default: boxed.box,
_$: boxed.box,
box: boxed.box,
createBox: boxed.createBox,
boxOnDemand: boxed.boxOnDemand,
// mostly for testing
util: util,
boxed: boxed,
};

@@ -24,3 +24,3 @@ /** internal

const BOXED_GET_THIS = "@@BOXED_THIS";
exports.BOXED_GET_THIS = BOXED_GET_THIS;
module.exports.BOXED_GET_THIS = BOXED_GET_THIS;

@@ -50,2 +50,8 @@ const BOXED_ARRAY_END = "";

},
get: {
get: function () {return this.getProp;},
set: function (value) {return false;},
delete: function () {return false;},
ownPropertyDescriptor: function () {return { value: this.getProp, /* writable: true, enumerable: false, configurable: false, get:UNDEFINED, set:UNDEFINED,*/ };},
},
default: {

@@ -148,3 +154,3 @@ get: function () {return this.setDefaultValue;},

exports.BoxedContext = BoxedContext;
module.exports.BoxedContext = BoxedContext;

@@ -204,3 +210,3 @@ // util.inherits(Boxed, InheritedClass);

exports.boxedContext = boxedContext;
module.exports.boxedContext = boxedContext;

@@ -234,3 +240,3 @@ /**

exports.Boxed = Boxed;
module.exports.Boxed = Boxed;

@@ -324,2 +330,6 @@ // util.inherits(Boxed, InheritedClass);

Boxed.prototype.getProp = function (prop) {
return this.get(this.context.wrapProp(prop));
};
Boxed.prototype.copyOfValue = function copyOfValue() {

@@ -340,3 +350,3 @@ return util.copyArrayObject(this.value);

// can't have boxed values here
const boxedValue = value[BOXED_GET_THIS];
const boxedValue = value && value[BOXED_GET_THIS];
if (boxedValue) {

@@ -693,11 +703,22 @@ value = boxedValue.valueOf();

if (isFunction(param)) {
let keys = value;
let i = keys.length;
while (i--) {
let prop = keys[i];
const item = value[prop];
if (item !== UNDEFINED) {
const boxedItem = this.get(prop);
param.call(UNDEFINED, boxedItem, prop, item);
if (isObject(value)) {
let keys = Object.keys(value);
let i = keys.length;
while (i--) {
let prop = keys[i];
const item = value[prop];
if (item !== UNDEFINED) {
const boxedItem = this.get(prop);
param.call(UNDEFINED, boxedItem, prop, item);
}
}
} else if (isArray(value)) {
let i = value.length;
while (i--) {
const item = value[i];
if (item !== UNDEFINED) {
const boxedItem = this.get(i);
param.call(UNDEFINED, boxedItem, i, item);
}
}
}

@@ -804,4 +825,31 @@ } else if (isObject(param)) {

function boxedProxy(boxed) {
boxed.boxedWith = boxed.boxedWith.bind(boxed);
boxed.detachFromParent = boxed.detachFromParent.bind(boxed);
boxed.detachProp = boxed.detachProp.bind(boxed);
boxed.detachAllProps = boxed.detachAllProps.bind(boxed);
boxed.has = boxed.has.bind(boxed);
boxed.ownKeys = boxed.ownKeys.bind(boxed);
boxed.getOwnPropertyDescriptor = boxed.getOwnPropertyDescriptor.bind(boxed);
boxed.getBoxedProp = boxed.getBoxedProp.bind(boxed);
boxed.get = boxed.get.bind(boxed);
boxed.getProp = boxed.getProp.bind(boxed);
boxed.copyOfValue = boxed.copyOfValue.bind(boxed);
boxed.set = boxed.set.bind(boxed);
boxed.delete = boxed.delete.bind(boxed);
boxed.valueOf = boxed.valueOf.bind(boxed);
boxed.setValueOf = boxed.setValueOf.bind(boxed);
boxed.deleteValueOf = boxed.deleteValueOf.bind(boxed);
boxed.isModified = boxed.isModified.bind(boxed);
boxed.valueOfModified = boxed.valueOfModified.bind(boxed);
boxed.setValueOfModified = boxed.setValueOfModified.bind(boxed);
boxed.deleteValueOfModified = boxed.deleteValueOfModified.bind(boxed);
boxed.setDefaultValue = boxed.setDefaultValue.bind(boxed);
boxed.boxedWith = boxed.boxedWith.bind(boxed);
boxed.unboxedDelta = boxed.unboxedDelta.bind(boxed);
boxed.setUnboxedDelta = boxed.setUnboxedDelta.bind(boxed);
boxed.deleteUnboxedDelta = boxed.deleteUnboxedDelta.bind(boxed);
boxed.unboxedDeepDelta = boxed.unboxedDeepDelta.bind(boxed);
boxed.setUnboxedDeepDelta = boxed.setUnboxedDeepDelta.bind(boxed);
boxed.deleteUnboxedDeepDelta = boxed.deleteUnboxedDeepDelta.bind(boxed);
boxed.boxedForEach = boxed.boxedForEach.bind(boxed);
boxed.boxedWith[BOXED_GET_THIS] = boxed;

@@ -856,5 +904,5 @@ boxed.proxiedThis = new Proxy(boxed.boxedWith, BoxedHandler);

// create customized context
exports.createBox = createBox;
module.exports.createBox = createBox;
exports.box = createBox();
module.exports.box = createBox();

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

this.boxed = UNDEFINED;
return this.saveState(modified, boxed);
if (this.saveState) {
return this.saveState(modified, boxed);
} else {
throw "Save State Not Supported on this instance, saveState callback not provided";
}
}

@@ -29,2 +33,3 @@ }

this.boxed = UNDEFINED;
return this.proxiedThis;
}

@@ -75,4 +80,2 @@

exports.BoxedOnDemand = BoxedOnDemand;
// util.inherits(Boxed, InheritedClass);

@@ -160,3 +163,3 @@

*/
function boxedOnDemand(getState, saveState, options) {
function boxOnDemand(getState, saveState, options) {
let boxed = new BoxedOnDemand(getState, saveState, options);

@@ -168,2 +171,3 @@ boxed.proxiedThis = new Proxy(boxed, BoxedOnDemandHandler);

// create customized context
exports.boxedOnDemand = boxedOnDemand;
module.exports.BoxedOnDemand = BoxedOnDemand;
module.exports.boxOnDemand = boxOnDemand;
"use strict";
const _ = require('lodash');
const isFunction = require('lodash.isfunction');
const isString = require('lodash.isstring');
exports.extend = function (other, add) {
module.exports.extend = function (other, add) {
// Don't do anything if add isn't an object

@@ -21,3 +22,3 @@ if (!add || !isObject(add)) return other;

exports.hasOwnProperty = hasOwnProperty;
module.exports.hasOwnProperty = hasOwnProperty;

@@ -36,3 +37,3 @@ function hasOwnProperties(arg) {

exports.hasOwnProperties = hasOwnProperties;
module.exports.hasOwnProperties = hasOwnProperties;

@@ -47,6 +48,6 @@ function isObject(param) {

exports.isString = _.isString;
exports.isArray = isArray;
exports.isObject = isObject;
exports.isFunction = _.isFunction;
module.exports.isString = isString;
module.exports.isArray = isArray;
module.exports.isObject = isObject;
module.exports.isFunction = isFunction;

@@ -58,3 +59,3 @@ function isNumeric(arg) {

exports.isNumeric = isNumeric;
module.exports.isNumeric = isNumeric;

@@ -66,3 +67,3 @@ function isNumericInteger(arg) {

exports.isNumericInteger = isNumericInteger;
module.exports.isNumericInteger = isNumericInteger;

@@ -73,3 +74,3 @@ function returnsAlwaysFalse() {

exports.returnsAlwaysFalse = returnsAlwaysFalse;
module.exports.returnsAlwaysFalse = returnsAlwaysFalse;

@@ -80,5 +81,5 @@ function returnsAlwaysTrue() {

exports.returnsAlwaysTrue = returnsAlwaysTrue;
module.exports.returnsAlwaysTrue = returnsAlwaysTrue;
exports.UNDEFINED = void 0;
module.exports.UNDEFINED = void 0;

@@ -89,3 +90,3 @@ function isUndefined(arg) {

exports.isUndefined = isUndefined;
module.exports.isUndefined = isUndefined;

@@ -96,3 +97,3 @@ function isNull(arg) {

exports.isNull = isNull;
module.exports.isNull = isNull;

@@ -103,3 +104,3 @@ function isNullOrUndefined(arg) {

exports.isNullOrUndefined = isNullOrUndefined;
module.exports.isNullOrUndefined = isNullOrUndefined;

@@ -110,3 +111,3 @@ function endsWith(value, suffix) {

exports.endsWith = endsWith;
module.exports.endsWith = endsWith;

@@ -117,3 +118,3 @@ function startsWith(value, prefix) {

exports.startsWith = startsWith;
module.exports.startsWith = startsWith;

@@ -124,3 +125,3 @@ function wrappedWith(value, prefix, suffix) {

exports.wrappedWith = wrappedWith;
module.exports.wrappedWith = wrappedWith;

@@ -138,3 +139,3 @@ function isWrapped(prop, prefixChars, suffixChars) {

exports.isWrapped = isWrapped;
module.exports.isWrapped = isWrapped;

@@ -158,3 +159,3 @@ function unwrap(prop, prefixChars, suffixChars) {

exports.unwrap = unwrap;
module.exports.unwrap = unwrap;

@@ -165,3 +166,3 @@ function wrap(prop, prefixChars, suffixChars) {

exports.wrap = wrap;
module.exports.wrap = wrap;

@@ -181,3 +182,3 @@ function copyFilteredProperties(dst, src, callBack) {

exports.copyFilteredProperties = copyFilteredProperties;
module.exports.copyFilteredProperties = copyFilteredProperties;

@@ -193,3 +194,3 @@ function copyArrayObject(src) {

exports.copyArrayObject = copyArrayObject;
module.exports.copyArrayObject = copyArrayObject;

@@ -204,6 +205,6 @@ function firstDefined() {

exports.firstDefined = firstDefined;
module.exports.firstDefined = firstDefined;
function deleteItems(arr) {
if (arguments.length > 1) {
if (arguments.length > 1 && isArray(arr)) {
let i = arguments.length;

@@ -221,2 +222,2 @@ while (--i) {

exports.deleteItems = deleteItems;
module.exports.deleteItems = deleteItems;
{
"name": "boxed-immutable",
"version": "0.1.5",
"version": "0.1.6",
"private": false,

@@ -13,11 +13,9 @@ "description": "Immutable proxy wrapper with auto-vivification",

},
"bundleDependencies": [],
"dependencies": {
"lodash": "^4.17.5"
"lodash.isfunction": "^3.0.9",
"lodash.isstring": "^4.0.1"
},
"devDependencies": {
"jest": "^22.4.3"
},
"scripts": {
"test": "jest"
},
"devDependencies": {},
"scripts": {},
"keywords": [

@@ -24,0 +22,0 @@ "immutable",

@@ -205,11 +205,12 @@ # boxed-immutable

| Property | Get | Set | Delete | Call |
|:---------------|:------------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:--------------------------|:-----------------------------------------------------------------------------------------------------------------|
| `_$` | proxy of the boxed object, ie. boxed === boxed.\_$, so you can do boxed.\_$() or boxed() | append end of array | error | does a call on first argument, use: `boxed._$(_$ => { });` returns `boxed` |
| `forEach$_$` | function | error | error | functions executes callback for each own property, passes `.forEach$_$((boxedValue, prop, unboxedValue) =>{});` |
| `unboxed$_$` | unboxed value | set value of boxed property and mark as modified | delete property in parent | error |
| `modified$_$` | value if modified else undefined | same as above | same as above | error |
| `default$_$` | function | set value if it is undefined, otherwise do nothing | error | error |
| `delta$_$` | modified properties of first level, full props thereafter: shallow delta | do shallow delta update of properties, all properties after first level will be changed | error | error |
| `deepDelta$_$` | modified properties only of all levels: deep delta | do deep delta update with value, only modified properties of all levels are changed. | error | error |
| Property | Get | Set | Delete | Call |
|:---------------|:------------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:--------------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------|
| `_$` | proxy of the boxed object, ie. boxed === boxed.\_$, so you can do boxed.\_$() or boxed() | append end of array | error | does a call on first argument, use: `boxed._$(_$ => { });` returns `boxed` |
| `get$_$` | function | error | error | `.get$_$("prop")` is same as `["prop" + "_$"]`, convenience function when you have a property name in a variabel and need a boxed version of it |
| `forEach$_$` | function | error | error | functions executes callback for each own property, passes `.forEach$_$((boxedValue, prop, unboxedValue) =>{});` |
| `unboxed$_$` | unboxed value | set value of boxed property and mark as modified | delete property in parent | error |
| `modified$_$` | value if modified else undefined | same as above | same as above | error |
| `default$_$` | function | set value if it is undefined, otherwise do nothing | error | error |
| `delta$_$` | modified properties of first level, full props thereafter: shallow delta | do shallow delta update of properties, all properties after first level will be changed | error | error |
| `deepDelta$_$` | modified properties only of all levels: deep delta | do deep delta update with value, only modified properties of all levels are changed. | error | error |

@@ -259,3 +260,3 @@ Use of `._$()`, sometimes you need to modify deep properties based on programming logic. Instead

### boxed-immutable boxedOnDemand
### boxed-immutable boxOnDemand

@@ -268,3 +269,3 @@ Provides a boxed proxy to immutable state, with `.save()` and `.cancel()` methods for saving or

```javascript
const boxedOnDemand = require('boxed-immutable').boxedOnDemand;
const boxOnDemand = require('boxed-immutable').boxOnDemand;

@@ -287,3 +288,3 @@ // your current function for returning immutable state object

// use in new getState to get boxed on demand
stateHolder = boxedOnDemand(undefined, () => {
stateHolder = boxOnDemand(undefined, () => {
return getSimpleState();

@@ -323,10 +324,10 @@ }, (modified, boxed) => {

|:---------|:---------|:------|:-------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `save` | function | error | error | calls the saveState callback passed to boxedOnDemand function, returns value returned from callback, callback only called if there were changes made to boxed object |
| `cancel` | function | error | error | cancels any changes and destroys the boxed object, it is recreated on next access with a fresh copy of the immutable state |
| `save` | function | error | error | calls the saveState callback passed to boxOnDemand function, returns value returned from callback, callback only called if there were changes made to boxed object |
| `cancel` | function | error | error | cancels any changes and destroys the boxed object, it is recreated on next access with a fresh copy of the immutable state, returns proxy this for chaining calls |
#### boxedOnDemand(getState, saveState, options)
#### boxOnDemand(getState, saveState, options)
```javascript
const boxedOnDemand = require('boxed-immutable').boxedOnDemand;
const onDemandState = boxedOnDemand();
const boxOnDemand = require('boxed-immutable').boxOnDemand;
const onDemandState = boxOnDemand();
```

@@ -333,0 +334,0 @@

"use strict";
let boxed = require("boxed-immutable");
let _$ = boxed._$;
let createBox = boxed.createBox;
let Boxed = boxed.Boxed;
let BOXED_GET_THIS = boxed.BOXED_GET_THIS;
const boxedImmutable = require("boxed-immutable");
const _$ = boxedImmutable._$;
const createBox = boxedImmutable.createBox;
const Boxed = boxedImmutable.boxed.Boxed;
const BOXED_GET_THIS = boxedImmutable.boxed.BOXED_GET_THIS;

@@ -313,1 +313,36 @@ function createBoxed(val) {

describe('Get prop', () => {
let origVal;
let boxedVal;
let boxedProxy;
let expectedValue;
let deltaValue;
let deepDeltaValue;
beforeAll(() => {
let vals = createBoxed({field1: ""});
origVal = vals.origVal;
boxedVal = vals.boxedVal;
boxedProxy = vals.boxedProxy;
boxedProxy.field1_$.default$_$ = 1;
boxedProxy.field2_$.default$_$ = 2;
boxedProxy.field2_$.default$_$ = 3;
boxedProxy.field3_$.default$_$(1);
boxedProxy.field3_$.default$_$(2);
boxedProxy.field3_$.default$_$(3);
expectedValue = {field1: "", field2: 2, field3:1, };
deepDeltaValue = deltaValue = {field2: 2, field3:1, };
});
test('[prop].prop fails', () => {
expect(()=>{let t= boxedProxy[field10].flag}).toThrow(ReferenceError);
});
test('get$_$(prop).prop succeeds', () => {
expect(boxedProxy.get$_$("field10").flag).toBe(undefined);
});
});
"use strict";
let boxed = require("boxed-immutable");
let _$ = boxed._$;
let createBox = boxed.createBox;
let Boxed = boxed.Boxed;
let BOXED_GET_THIS = boxed.BOXED_GET_THIS;
const boxedImmutable = require("boxed-immutable");
const _$ = boxedImmutable._$;
const createBox = boxedImmutable.createBox;
const Boxed = boxedImmutable.boxed.Boxed;
const BOXED_GET_THIS = boxedImmutable.boxed.BOXED_GET_THIS;

@@ -9,0 +9,0 @@ function createBoxed(val) {

"use strict";
let boxed = require("boxed-immutable");
let _$ = boxed._$;
let boxedOnDemand = boxed.boxedOnDemand;
let createBox = boxed.createBox;
let Boxed = boxed.Boxed;
let BoxedOnDemand = boxedOnDemand.BoxedOnDemand;
let BOXED_GET_THIS = boxed.BOXED_GET_THIS;
const boxedImmutable = require("boxed-immutable");
const _$ = boxedImmutable._$;
const createBox = boxedImmutable.createBox;
const BOXED_GET_THIS = boxedImmutable.boxed.BOXED_GET_THIS;
const boxOnDemand = boxedImmutable.boxOnDemand;
const BoxedOnDemand = boxedImmutable.boxed.BoxedOnDemand;
const Boxed = boxedImmutable.boxed.Boxed;
function createBoxed(get, set) {
const boxedProxy = boxedOnDemand(get, set);
const boxedProxy = boxOnDemand(get, set);
return {

@@ -363,3 +363,19 @@ boxedProxy: boxedProxy,

});
test('chain cancel', () => {
boxedProxy._$.simple = 0;
let retVal = boxedProxy.cancel();
retVal._$.simple = 0;
retVal.save();
expect(origVal).toEqual({"deepDelta": {"simple": 0}, "delta": {"simple": 0}, "state": {"simple": 0}});
});
test('set value to null', () => {
boxedProxy._$.simple = null;
let retVal = boxedProxy.cancel();
retVal._$.simple = null;
retVal.save();
expect(origVal).toEqual({"deepDelta": {"simple": null}, "delta": {"simple": null}, "state": {"simple": null}});
});
});

@@ -6,2 +6,4 @@ # Version History

- [0.1.6](#016)
- [0.1.5](#015)
- [0.1.4](#014)

@@ -14,19 +16,31 @@ - [0.1.3](#013)

## 0.1.6
* Fix: setting null values would cause NPE.
* Fix: unbound functions would sometimes fail
## 0.1.5
* Change: move function to util
## 0.1.4
* Fix: deep delta would not include properties for which proxy was created after the property
was already modified in the parent.
* Add: `default$_$` magic property which only changes value if it is `undefined`, otherwise a
noop. Use: `boxed.field_$.default$_$ = value;` or `boxed.field_$.default$_$(value)`
* Add: `boxedOnDemand` proxy wrapper to allow creating a boxed state with `save()` and
`cancel()` methods. It provides a new copy of the state if it has changed from last access.
* Fix: deep delta would not include properties for which proxy was
created after the property was already modified in the parent.
* Add: `default$_$` magic property which only changes value if it is
`undefined`, otherwise a noop. Use: `boxed.field_$.default$_$ =
value;` or `boxed.field_$.default$_$(value)`
* Add: `boxOnDemand` proxy wrapper to allow creating a boxed state with
`save()` and `cancel()` methods. It provides a new copy of the state
if it has changed from last access.
## 0.1.3
* Fix: remove endsWith/startsWith on strings. Need to get babel and polyfill presets figured
out. for now works in a react app.
* Fix: remove endsWith/startsWith on strings. Need to get babel and
polyfill presets figured out. for now works in a react app.
## 0.1.2
* Fix: clean out node_modules to detect extraneous requires which are not used
* Fix: clean out node_modules to detect extraneous requires which are
not used

@@ -33,0 +47,0 @@ ## 0.1.1

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc