1.0.46 • Published 5 years ago

xyjax-update-immutable v1.0.46

Weekly downloads
14
License
MIT
Repository
github
Last release
5 years ago

npm npm bundle size npm NPM

About

xyjax-update-immutable is the standalone and lightweight system which provides functional-programming-like deep-cloned objects copy/merge (which is extremely useful for Redux e.g.). This package was originally developed for Xyjax NPM package.

Methods

There is one method you can import:

1. updateImmutable(path, changes)(sourceObject)

Returns changed deep-copy of given object, source object won't be affected.

Arguments description:

  • path is the string representation of path ('a.b.c' for example) must be changed or created in object copy will be returned
  • changes is the payload will be applied to changed source object copy (it can be primitive, object or calculating field function - see examples below)
  • sourceObject is the object which changed copy will be returned

Usage example

Click here to take a look at RunKit + NPM embed example.

import { updateImmutable } from 'xyjax-update-immutable'

var target_1 = {}
//changes can be primitives...
var target_2 = updateImmutable('a.b', 4)(target_1)
//...objects...
var target_3 = updateImmutable('c', {d: 5})(target_2)
//...or calculating fields (with default parameters in case of field is not found)
var target_4 = updateImmutable('c.d', (x = 0) => { return x * 2 })(target_3)
//any of this approaches work at any nested level (calculating field as example)
var target_5 = updateImmutable('a.b.c.d.e.f.g', (x = 5) => { return x * Math.random() })(target_1)

console.log(target_1) // {}
console.log(target_2) // {a: {b: 4}}
console.log(target_3) // {a: {b: 4}, c: {d: 5}}
console.log(target_4) // {a: {b: 4}, c: {d: 10}}
console.log(target_5) // {a: {b: {c: {d: {e: {f: {g: 3.4901662472336725}}}}}}}
1.0.46

5 years ago

1.0.45

5 years ago

1.0.44

5 years ago

1.0.43

5 years ago

1.0.42

5 years ago

1.0.41

5 years ago

1.0.40

5 years ago

1.0.39

5 years ago

1.0.38

5 years ago

1.0.37

5 years ago

1.0.36

5 years ago

1.0.35

5 years ago

1.0.34

5 years ago

1.0.33

5 years ago

1.0.32

5 years ago

1.0.31

5 years ago

1.0.30

5 years ago

1.0.29

5 years ago

1.0.28

5 years ago

1.0.27

5 years ago

1.0.26

5 years ago

1.0.25

5 years ago

1.0.24

5 years ago

1.0.23

5 years ago

1.0.22

5 years ago

1.0.21

5 years ago

1.0.20

5 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago