typescript-immutable-replicator
Version:
Typesafe, refactorable Typescript replicator for immutable objects
47 lines (32 loc) • 2.06 kB
Markdown
# typescript-immutable-replicator
Typesafe, refactorable cloning and modifying of immutable objects with typescript
[](https://nodei.co/npm/typescript-immutable-replicator/)
## Replicator
Replicator is a tool to replicate and modify immutable objects.

### Characteristics
###### typesafe properties

###### typesafe property values

###### chainable

###### refactorable and easy to read
### Usage
1. Load an object by calling `ReplicationBuilder.forObject()`
2. Navigate down the object tree through the typesafe function `getChild()`
3. Modify a property with either
- `modify('prop').to(newValue:T)` or
- `modify('prop').by((T) => newValue:T)` for example `((oldValue) => oldValue + newValue)`
4. Repeat step 3 and 4 until all modifications are done
5. Produce the replica with `build()`
### Examples


### Behaviour
- deep copies the source object
- freeze in --> freeze out. If the source object was frozen (for detecting manipulations while development), then the produced replica will also be deep frozen.
- warning if source object is not deep frozen (produced replica will be deep frozen)
## DeepFreeze
`deepFreeze()` applies Object.freeze() recursively on an object to make it immutable
`isDeepFrozen()` checks if an object is recursively frozen.