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

Commitb33dc3b

Browse files
committed
fix: prevent unnecessary subscriptions when using CombineSelector
1 parent5fe2ae9 commitb33dc3b

File tree

11 files changed

+66
-105
lines changed

11 files changed

+66
-105
lines changed

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ Store.Select(SelectIsPageSelected, "mainPage")
283283

284284
###Combine selectors
285285

286-
Sometimes, you need to consume multiple selectors. In some cases, you just want to combine them. This is what you can do with`CombineSelectors` function.It uses`CombineLatest` operator of the Rx.NET library.Here is an example:
286+
Sometimes, you need to consume multiple selectors. In some cases, you just want to combine them. This is what you can do with`CombineSelectors` function. Here is an example:
287287

288288
```csharp
289289
Store.Select(

‎ReduxSimple.DevTools/ReduxSimple.DevTools.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<RootNamespace>ReduxSimple.DevTools</RootNamespace>
66
<PackageId>ReduxSimple.DevTools</PackageId>
7-
<Version>3.3.0-preview001</Version>
7+
<Version>3.4.0-preview001</Version>
88
<Authors>David Bottiau</Authors>
99
<Title>ReduxSimple DevTools</Title>
1010
<Description>Simple Stupid Redux Store using Reactive Extensions</Description>

‎ReduxSimple.Entity/ReduxSimple.Entity.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<RootNamespace>ReduxSimple.Entity</RootNamespace>
66
<PackageId>ReduxSimple.Entity</PackageId>
7-
<Version>3.3.0-preview001</Version>
7+
<Version>3.4.0-preview001</Version>
88
<Authors>David Bottiau</Authors>
99
<Title>ReduxSimple Entity Management</Title>
1010
<Description>Simple Stupid Redux Store using Reactive Extensions</Description>

‎ReduxSimple.Tests.Setup/TodoListStore/Actions.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ public class SwitchUserAction
99
{
1010
publicstring?NewUser{get;set;}
1111
}
12+
13+
publicclassResetStateAction{}
1214
}

‎ReduxSimple.Tests.Setup/TodoListStore/Functions.cs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ public static TodoListState CreateInitialTodoListState()
3232
NewUser=newUser
3333
});
3434
}
35-
35+
36+
publicstaticvoidDispatchResetAction<T>(ReduxStore<T>store)whereT:class,new()
37+
{
38+
store.Dispatch(newResetStateAction());
39+
}
40+
3641
publicstaticvoidDispatchAllActions<T>(ReduxStore<T>store)whereT:class,new()
3742
{
3843
DispatchAddTodoItemAction(store,1,"Create unit tests");

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
usingConverto;
22
usingSystem.Collections.Generic;
33
usingstaticReduxSimple.Reducers;
4+
usingstaticReduxSimple.Tests.Setup.TodoListStore.Functions;
45

56
namespaceReduxSimple.Tests.Setup.TodoListStore
67
{
@@ -31,6 +32,9 @@ public static IEnumerable<On<TodoListState>> CreateReducers()
3132
CurrentUser=action.NewUser
3233
}
3334
)
35+
),
36+
On<ResetStateAction,TodoListState>(
37+
(state,action)=>CreateInitialTodoListState()
3438
)
3539
};
3640
}

‎ReduxSimple.Tests/SelectorTest.cs‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,5 +228,39 @@ public void CanCombineSelectorsWithOneUpdatedPropertyAndOneNonUpdateProperty()
228228
Assert.Equal(2,lastPartialState.todoList?.Count);
229229
Assert.Null(lastPartialState.uselessProperty);
230230
}
231+
232+
[Fact]
233+
publicvoidCanCombineSelectorsWithSynchronousStateUpdates()
234+
{
235+
// Arrange
236+
varinitialState=CreateInitialTodoListState();
237+
varstore=newTodoListStore(
238+
Setup.TodoListStore.Reducers.CreateReducers(),
239+
initialState
240+
);
241+
242+
// Act
243+
intobserveCount=0;
244+
(IImmutableList<TodoItem>?todoList,string?currentUser)lastPartialState=(null,null);
245+
246+
store.Select(
247+
CombineSelectors(SelectTodoList,SelectCurrentUser)
248+
)
249+
.Subscribe(x=>
250+
{
251+
var(todolist,currentUser)=x;
252+
253+
observeCount++;
254+
lastPartialState=(todolist,currentUser);
255+
});
256+
257+
DispatchAllActions(store);
258+
DispatchResetAction(store);
259+
260+
// Assert
261+
Assert.Equal(6,observeCount);
262+
Assert.Equal(0,lastPartialState.todoList?.Count);
263+
Assert.Equal("David",lastPartialState.currentUser);
264+
}
231265
}
232266
}

‎ReduxSimple.Uwp.DevTools/ReduxSimple.Uwp.DevTools.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<TargetFramework>uap10.0.18362</TargetFramework>
44
<RootNamespace>ReduxSimple.Uwp.DevTools</RootNamespace>
55
<PackageId>ReduxSimple.Uwp.DevTools</PackageId>
6-
<Version>3.3.0-preview001</Version>
6+
<Version>3.4.0-preview001</Version>
77
<Authors>David Bottiau</Authors>
88
<Title>ReduxSimple DevTools for UWP</Title>
99
<Description>Simple Stupid Redux Store using Reactive Extensions - DevTools for UWP applications</Description>

‎ReduxSimple.Uwp.RouterStore/ReduxSimple.Uwp.RouterStore.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<TargetFramework>uap10.0.16299</TargetFramework>
44
<RootNamespace>ReduxSimple.Uwp.RouterStore</RootNamespace>
55
<PackageId>ReduxSimple.Uwp.RouterStore</PackageId>
6-
<Version>3.3.0-preview001</Version>
6+
<Version>3.4.0-preview001</Version>
77
<Authors>David Bottiau</Authors>
88
<Title>ReduxSimple Router Store for UWP</Title>
99
<Description>Simple Stupid Redux Store using Reactive Extensions - Binding between Store and Routing in UWP applications</Description>

‎ReduxSimple/ReduxSimple.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<PackageId>ReduxSimple</PackageId>
6-
<Version>3.3.0</Version>
6+
<Version>3.4.0</Version>
77
<Authors>David Bottiau</Authors>
88
<Description>Simple Stupid Redux Store using Reactive Extensions</Description>
99
<PackageProjectUrl>https://github.com/Odonno/ReduxSimple</PackageProjectUrl>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp