Skip to content

Commit 0f07699

Browse files
author
Maier, Martin
committed
* applied readme
1 parent c7bf891 commit 0f07699

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

README.md

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,47 @@ Helpers for handling immutable objects with typescript
88
Replicator is a tool to replicate and modify immutable objects.
99

1010
### Syntax
11-
![image](https://user-images.githubusercontent.com/20232625/28767484-22a1d330-75d4-11e7-9667-01271c7e2448.png)
11+
##### simply replace property by with new value
12+
```Typescript
13+
return ReplicationBuilder.forObject(state).getProperty('party').replaceProperty('name').with('MyParty').build()
14+
```
15+
##### replace property depending on old value
16+
```Typescript
17+
return ReplicationBuilder.forObject(state).getProperty('party').replaceProperty('partymemberArray').by((oldPartymemberArray) => [...oldPartymemberArray, 'new partymember']).build()
18+
```
19+
##### clone property and apply some function on it
20+
```Typescript
21+
return ReplicationBuilder.forObject(state).replaceProperty('party').andDo((clonedParty) => clonedParty.addPartyMember('new partymember')).build()
22+
```
1223

1324
### Characteristics
14-
###### typesafe properties
25+
##### typesafe properties
26+
1527
![image](https://user-images.githubusercontent.com/20232625/28767468-14cb5aa6-75d4-11e7-8193-dcf828133035.png)
16-
###### typesafe property values
28+
##### typesafe property values
29+
1730
![image](https://user-images.githubusercontent.com/20232625/28767500-3b6f082e-75d4-11e7-8ec3-1e1392209396.png)
18-
###### chainable
19-
![image](https://user-images.githubusercontent.com/20232625/28767664-dc00269c-75d4-11e7-9c6d-c179c0b12eaf.png)
31+
##### chainable
32+
```Typescript
33+
return ReplicationBuilder.forObject(state)
34+
.getProperty('party').replaceProperty('name').with('MyParty').replaceProperty('members').by((members) => [...members, newMember])
35+
.getProperty('initiator').replaceProperty('prename').with('Party').replaceProperty('surname').with('guy')
36+
.build();
37+
```
2038
###### refactorable and easy to read
2139

2240
### Usage
2341

2442
1. Load an object by calling `ReplicationBuilder.forObject()`
2543
2. Navigate down the object tree through the typesafe function `getChild()`
26-
3. Modify a property with either
27-
- `modify('prop').to(newValue:T)` or
28-
- `modify('prop').by((T) => newValue:T)` for example `((oldValue) => oldValue + newValue)`
29-
   - `delete('prop')` to remove the property in the resulting object
44+
3. Modify a property with either (see syntax paragraph above)
45+
- `replaceProperty('prop').with(newValue:T)`
46+
- `replaceProperty('prop').by((T) => newValue:T)`
47+
- `replaceProperty('prop').andDo((clonedProp) => clonedProp.doSomething()`
48+
- `removeProperty('prop')` to remove the property in the resulting object
3049
4. Repeat step 3 and 4 until all modifications are done
3150
5. Produce the replica with `build()`
3251

33-
### Examples
34-
35-
![image](https://user-images.githubusercontent.com/20232625/28767484-22a1d330-75d4-11e7-9667-01271c7e2448.png)
36-
37-
![image](https://user-images.githubusercontent.com/20232625/28767522-55f40ea6-75d4-11e7-8faf-0c1bf9f91953.png)
38-
3952
### Behaviour
4053

4154
- deep copies the source object

0 commit comments

Comments
 (0)