Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4e4842d

Browse files
committed
doc: use of with keyword
1 parent6081efd commit4e4842d

File tree

15 files changed

+69
-76
lines changed

15 files changed

+69
-76
lines changed

‎README.md‎

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ You will need to follow the following steps to create your own Redux Store:
3636
1. Create`State` definition
3737

3838
```csharp
39-
publicclassRootState
39+
publicrecordRootState
4040
{
4141
publicstringCurrentPage {get;set; }=string.Empty;
4242
publicImmutableArray<string>Pages {get;set; }=ImmutableArray<string>.Empty;
4343
}
4444
```
4545

46-
Each State should immutable. That's why we prefer to use immutable types for each property of the State.
46+
Each State shouldbeimmutable. That's why we prefer to use immutable types for each property of the State.
4747

4848
2. Create`Action` definitions
4949

@@ -68,23 +68,24 @@ public static class Reducers
6868
returnnewList<On<RootState>>
6969
{
7070
On<NavigateAction,RootState>(
71-
(state,action)=>state.With(new{Pages=state.Pages.Add(action.PageName) })
71+
(state,action)=>statewith{Pages=state.Pages.Add(action.PageName) }
7272
),
7373
On<GoBackAction,RootState>(
7474
state=>
7575
{
7676
varnewPages=state.Pages.RemoveAt(state.Pages.Length-1);
77-
returnstate.With(new {
77+
78+
returnstatewith {
7879
CurrentPage=newPages.LastOrDefault(),
7980
Pages=newPages
80-
});
81+
};
8182
}
8283
),
8384
On<ResetAction,RootState>(
84-
state=>state.With(new {
85+
state=>statewith {
8586
CurrentPage=string.Empty,
8687
Pages=ImmutableArray<string>.Empty
87-
})
88+
}
8889
)
8990
};
9091
}
@@ -158,23 +159,24 @@ You can define a list of `On` functions where at least one action can be trigger
158159
returnnewList<On<RootState>>
159160
{
160161
On<NavigateAction,RootState>(
161-
(state,action)=>state.With(new{Pages=state.Pages.Add(action.PageName) })
162+
(state,action)=>statewith{Pages=state.Pages.Add(action.PageName) }
162163
),
163164
On<GoBackAction,RootState>(
164165
state=>
165166
{
166167
varnewPages=state.Pages.RemoveAt(state.Pages.Length-1);
167-
returnstate.With(new {
168+
169+
returnstatewith {
168170
CurrentPage=newPages.LastOrDefault(),
169171
Pages=newPages
170-
});
172+
};
171173
}
172174
),
173175
On<ResetAction,RootState>(
174-
state=>state.With(new {
176+
state=>statewith {
175177
CurrentPage=string.Empty,
176178
Pages=ImmutableArray<string>.Empty
177-
})
179+
}
178180
)
179181
};
180182
```
@@ -195,8 +197,8 @@ First you need to create a new state lens for feature/nested states:
195197
publicstaticIEnumerable<On<RootState>>GetReducers()
196198
{
197199
returnCreateSubReducers(SelectCounterState)
198-
.On<IncrementAction>(state=>state.With(new{Count=state.Count+1 }))
199-
.On<DecrementAction>(state=>state.With(new{Count=state.Count-1 }))
200+
.On<IncrementAction>(state=>statewith{Count=state.Count+1 })
201+
.On<DecrementAction>(state=>statewith{Count=state.Count-1 })
200202
.ToList();
201203
}
202204
```
@@ -532,7 +534,7 @@ When dealing with entities, you often repeat the same process to add, update and
532534
1. Start creating an`EntityState` and an`EntityAdapter`
533535

534536
```csharp
535-
publicclassTodoItemEntityState :EntityState<int,TodoItem>
537+
publicrecordTodoItemEntityState :EntityState<int,TodoItem>
536538
{
537539
}
538540

@@ -545,7 +547,7 @@ public static class Entities
545547
2. Use the`EntityState` in your state
546548

547549
```csharp
548-
publicclassTodoListState
550+
publicrecordTodoListState
549551
{
550552
publicTodoItemEntityStateItems {get;set; }
551553
publicTodoFilterFilter {get;set; }
@@ -558,10 +560,10 @@ public class TodoListState
558560
On<CompleteTodoItemAction,TodoListState>(
559561
(state,action)=>
560562
{
561-
returnstate.With(new
563+
returnstatewith
562564
{
563565
Items=TodoItemAdapter.UpsertOne(new {action.Id,Completed=true },state.Items)
564-
});
566+
};
565567
}
566568
)
567569
```

‎ReduxSimple.Entity/EntityState.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/// </summary>
66
/// <typeparam name="TKey"></typeparam>
77
/// <typeparam name="TEntity"></typeparam>
8-
publicabstractclassEntityState<TKey,TEntity>
8+
publicabstractrecordEntityState<TKey,TEntity>
99
{
1010
/// <summary>
1111
/// List of all the primary keys (ids) in the collection.

‎ReduxSimple.Entity/EntityStateAdapter.cs‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ public TEntityState AddAll<TEntityState>(IEnumerable<TEntity> entities, TEntityS
3131
whereTEntityState:EntityState<TKey,TEntity>
3232
{
3333
varcollection=entities.ToDictionary(SelectId);
34-
returnstate.With(new
34+
35+
returnstatewith
3536
{
3637
Ids=collection.Keys.ToList(),
3738
Collection=collection
38-
});
39+
};
3940
}
4041

4142
/// <summary>
@@ -94,11 +95,11 @@ public TEntityState UpsertMany<TEntityState, TPartialEntity>(IEnumerable<TPartia
9495
.Concat(updatedEntities)
9596
.ToDictionary(SelectId);
9697

97-
returnstate.With(new
98+
returnstatewith
9899
{
99100
Ids=collection.Keys.ToList(),
100101
Collection=collection
101-
});
102+
};
102103
}
103104

104105
/// <summary>
@@ -131,11 +132,11 @@ public TEntityState RemoveMany<TEntityState>(IEnumerable<TKey> keys, TEntityStat
131132
)
132133
.ToDictionary(SelectId);
133134

134-
returnstate.With(new
135+
returnstatewith
135136
{
136137
Ids=collection.Keys.ToList(),
137138
Collection=collection
138-
});
139+
};
139140
}
140141

141142
/// <summary>
@@ -148,11 +149,11 @@ public TEntityState RemoveAll<TEntityState>(TEntityState state)
148149
whereTEntityState:EntityState<TKey,TEntity>
149150
{
150151
varcollection=newDictionary<TKey,TEntity>();
151-
returnstate.With(new
152+
returnstatewith
152153
{
153154
Ids=collection.Keys.ToList(),
154155
Collection=collection
155-
});
156+
};
156157
}
157158

158159
/// <summary>
@@ -168,10 +169,10 @@ public TEntityState Map<TEntityState>(Func<TEntity, TEntity> map, TEntityState s
168169
varentities=state.Collection.Values.Select(map);
169170
varcollection=entities.ToDictionary(SelectId);
170171

171-
returnstate.With(new
172+
returnstatewith
172173
{
173174
Ids=collection.Keys.ToList(),
174175
Collection=collection
175-
});
176+
};
176177
}
177178
}

‎ReduxSimple.Tests.Setup/MultiReduceStore/Reducers.cs‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
usingConverto;
2-
usingstaticReduxSimple.Reducers;
1+
usingstaticReduxSimple.Reducers;
32

43
namespaceReduxSimple.Tests.Setup.MultiReduceStore;
54

@@ -10,13 +9,13 @@ public static IEnumerable<On<MultiReduceState>> CreateReducers()
109
returnnewList<On<MultiReduceState>>
1110
{
1211
On<UpdateNumberAction,MultiReduceState>(
13-
(state,action)=>state.With(new{Number1=action.Number})
12+
(state,action)=>statewith{Number1=action.Number}
1413
),
1514
On<UpdateNumberAction,MultiReduceState>(
16-
(state,action)=>state.With(new{Number2=action.Number})
15+
(state,action)=>statewith{Number2=action.Number}
1716
),
1817
On<UpdateNumberAction,MultiReduceState>(
19-
(state,action)=>state.With(new{Number3=action.Number})
18+
(state,action)=>statewith{Number3=action.Number}
2019
)
2120
};
2221
}

‎ReduxSimple.Tests.Setup/MultiReduceStore/State.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespaceReduxSimple.Tests.Setup.MultiReduceStore;
22

3-
publicclassMultiReduceState
3+
publicrecordMultiReduceState
44
{
55
publicintNumber1{get;set;}
66
publicintNumber2{get;set;}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
usingConverto;
2-
usingstaticReduxSimple.Reducers;
1+
usingstaticReduxSimple.Reducers;
32
usingstaticReduxSimple.Tests.Setup.NestedArrayStore.Selectors;
43

54
namespaceReduxSimple.Tests.Setup.NestedArrayStore;
@@ -11,17 +10,17 @@ public static IEnumerable<On<RootState>> GetReducersFromImplicitLens()
1110
returnCreateSubReducers(
1211
SelectNested1
1312
)
14-
.On<UpdateNumberAction>((state,action)=>state.With(new{RandomNumber=action.Number}))
13+
.On<UpdateNumberAction>((state,action)=>statewith{RandomNumber=action.Number})
1514
.ToList();
1615
}
1716

1817
publicstaticIEnumerable<On<RootState>>GetReducersFromExplicitLens()
1918
{
2019
returnCreateSubReducers(
2120
SelectNested1,
22-
(state,featureState)=>state.With(new{States=state.States.SetItem(0,featureState)})
21+
(state,featureState)=>statewith{States=state.States.SetItem(0,featureState)}
2322
)
24-
.On<UpdateNumberAction>((state,action)=>state.With(new{RandomNumber=action.Number}))
23+
.On<UpdateNumberAction>((state,action)=>statewith{RandomNumber=action.Number})
2524
.ToList();
2625
}
2726
}

‎ReduxSimple.Tests.Setup/NestedArrayStore/State.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespaceReduxSimple.Tests.Setup.NestedArrayStore;
22

3-
publicclassRootState
3+
publicrecordRootState
44
{
55
publicImmutableArray<NestedState>States{get;set;}
66

@@ -19,7 +19,7 @@ public class RootState
1919
};
2020
}
2121

22-
publicclassNestedState
22+
publicrecordNestedState
2323
{
2424
publicint?RandomNumber{get;set;}
2525

‎ReduxSimple.Tests.Setup/NestedStore/Reducers.cs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
usingConverto;
2-
usingstaticReduxSimple.Reducers;
1+
usingstaticReduxSimple.Reducers;
32

43
namespaceReduxSimple.Tests.Setup.NestedStore;
54

@@ -10,7 +9,7 @@ public static IEnumerable<On<NestedState>> CreateReducers()
109
returnnewList<On<NestedState>>
1110
{
1211
On<UpdateNumberAction,NestedState>(
13-
(state,action)=>state.With(new{RandomNumber=action.Number})
12+
(state,action)=>statewith{RandomNumber=action.Number}
1413
)
1514
};
1615
}

‎ReduxSimple.Tests.Setup/NestedStore/State.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespaceReduxSimple.Tests.Setup.NestedStore;
22

3-
publicclassRootState
3+
publicrecordRootState
44
{
55
publicNestedState?Nested{get;set;}
66

@@ -11,7 +11,7 @@ public class RootState
1111
};
1212
}
1313

14-
publicclassNestedState
14+
publicrecordNestedState
1515
{
1616
publicint?RandomNumber{get;set;}
1717

‎ReduxSimple.Tests.Setup/ReusedStateStore/Reducers.cs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
usingConverto;
2-
usingstaticReduxSimple.Reducers;
1+
usingstaticReduxSimple.Reducers;
32

43
namespaceReduxSimple.Tests.Setup.ReusedStateStore;
54

@@ -10,7 +9,7 @@ public static IEnumerable<On<NestedState>> CreateReducers()
109
returnnewList<On<NestedState>>
1110
{
1211
On<UpdateNumberAction,NestedState>(
13-
(state,action)=>state.With(new{RandomNumber=action.Number})
12+
(state,action)=>statewith{RandomNumber=action.Number}
1413
)
1514
};
1615
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp