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.0 to 0.1.1

2

lib/util.js

@@ -42,3 +42,3 @@ "use strict";

export function isArray(param) {
function isArray(param) {
return isObject(param) && param.constructor === Array;

@@ -45,0 +45,0 @@ }

{
"name": "boxed-immutable",
"version": "0.1.0",
"version": "0.1.1",
"private": false,

@@ -5,0 +5,0 @@ "description": "Immutable proxy wrapper with auto-vivification",

@@ -21,4 +21,4 @@ # boxed-immutable

Create a boxed-immutable object proxy then access and/or modify its nested properties, ignoring whether
intermediate values are objects/arrays or whether they exist.
Create a boxed-immutable object proxy then access and/or modify its nested properties, ignoring
whether intermediate values are objects/arrays or whether they exist.

@@ -71,3 +71,3 @@ Original object/array are shallow copied on first modification (all the way back to the root

// anything accessed via proxied properties (ending in _$) could be undefined, null, or anything that would throw a TypeError, the result is undefined
let caption = boxed.appState_$.dashboard[dashboardName + "_$"].captionText || 'default caption';
let caption = boxed.appState_$.dashboard_$[dashboardName + "_$"].captionText || 'default caption';

@@ -78,3 +78,3 @@ // would work just as well

// everything could be completely empty, the end result is undefined
let caption = boxed.appState_$.dashboard[dashboardName + "_$"].captionText || 'default caption';
let caption = boxed.appState_$.dashboard_$[dashboardName + "_$"].captionText || 'default caption';

@@ -119,14 +119,13 @@ ```

empty["field"] = 5;
empty.field = 5; // if you know its empty can also do empty[0] however if you are wrong then the latter will overwrite the value at 0
empty.field = 5;
// result: {field: 5}
empty._$ = 10;
// result: [5, 10]
// result: {0: 10, field: 5}
empty._$ = 20;
let result = empty.unboxed$_$;
// result: [5, 10, 20]
// result: {0: 10, 1: 20, field: 5}
```
For symmetry, you can also use `_$` on objects. In case of objects `_$` is equal to the greatest

@@ -146,3 +145,3 @@ integer key in the object or 0 if no integer keys. Here is why:

// the same can be achieved with
// the same can be achieved with, without having to increment the index
obj.prop = "a";

@@ -178,3 +177,2 @@ obj[_$] = 5;

| Option | Default | Description |

@@ -205,16 +203,16 @@ |:-----------------------------------|:------------|:-----------------------------------------------------------------------------------------|

With default settings all magic properties except `_$` get an extra `$` added because of the default `magicSuffixChars` being `"$"`
With default settings all magic properties except `_$` get an extra `$` added because of the
default `magicSuffixChars` being `"$"`
Magic Properties of boxed properties:
| 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 or first use as `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 |
| `delta$_$` | modified properties of first leve, all props thereafter, shallow delta | do shallow delta update of properties, all properties after first level will be changed | error | error |
| `deepDelta$_$` | modified properties 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` |
| `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 |
| `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 |
Use of `._$()`, sometimes you need to modify deep properties based on programming logic. Instead

@@ -239,5 +237,5 @@ of creating an object then adding it to your modified state, you can use this option and benefit

:warning: When a property is set through the parent collection it orphans the boxed state for
all the properties that the parent for which you kept reference. These detached properties will
still work but only on their own copy of the data since they are now the detached from the root.
:warning: When a value is set on the parent collection it orphans the boxed state for
all the properties of the parent for which you kept reference. These detached properties will
still work but only on their own copy of the data since they are now detached from the root.

@@ -255,3 +253,3 @@ For example this will happen when you do something like:

boxed.level1_$.level2_$.level3 = [0,1,2];
boxed.level1_$.level2_$.level3 = [0,1,2]; // this will detach all boxed properties from level3 and below, like nested

@@ -267,3 +265,4 @@ nested[_$] = 3;

MIT, see [LICENSE.md](http://github.com/vsch/boxed-immutable/blob/master/LICENSE.md) for details.
MIT, see [LICENSE.md](http://github.com/vsch/boxed-immutable/blob/master/LICENSE.md) for
details.

@@ -6,5 +6,10 @@ # Version History

- [0.1.1](#011)
- [0.1.0](#010)
## 0.1.1
* Fix: remove straggler export keyword
## 0.1.0

@@ -11,0 +16,0 @@

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