0.3.2 • Published 7 years ago
typescript-immutable-replicator v0.3.2
typescript-immutable-replicator
Typesafe, refactorable cloning and modifying of immutable objects with typescript
Replicator
Replicator is a tool to replicate and modify immutable objects.
Characteristics
typesafe properties
typesafe property values
chainable
refactorable and easy to read
Usage
- Load an object by calling
ReplicationBuilder.forObject()
- Navigate down the object tree through the typesafe function
getChild()
- Modify a property with either
modify('prop').to(newValue:T)
ormodify('prop').by((T) => newValue:T)
for example((oldValue) => oldValue + newValue)
- Repeat step 3 and 4 until all modifications are done
- 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.