Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
Neos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
love_飞影
Neos
Commits
a2b4da13
Commit
a2b4da13
authored
Nov 26, 2022
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
udpate handSlice
parent
334da341
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
3 deletions
+39
-3
src/reducers/duel/handsSlice.ts
src/reducers/duel/handsSlice.ts
+30
-2
src/reducers/duel/mod.ts
src/reducers/duel/mod.ts
+9
-1
No files found.
src/reducers/duel/handsSlice.ts
View file @
a2b4da13
import
{
PayloadAction
,
CaseReducer
}
from
"
@reduxjs/toolkit
"
;
import
{
PayloadAction
,
CaseReducer
,
createAsyncThunk
,
ActionReducerMapBuilder
,
}
from
"
@reduxjs/toolkit
"
;
import
{
DuelState
}
from
"
./mod
"
;
import
{
DuelState
}
from
"
./mod
"
;
import
{
RootState
}
from
"
../../store
"
;
import
{
RootState
}
from
"
../../store
"
;
import
{
CardMeta
}
from
"
../../api/cards
"
;
import
{
CardMeta
,
fetchCard
}
from
"
../../api/cards
"
;
export
interface
Hands
{
export
interface
Hands
{
cards
:
CardMeta
[];
cards
:
CardMeta
[];
...
@@ -37,6 +42,29 @@ export const opAddHandsImpl: CaseReducer<DuelState, PayloadAction<number[]>> = (
...
@@ -37,6 +42,29 @@ export const opAddHandsImpl: CaseReducer<DuelState, PayloadAction<number[]>> = (
}
}
};
};
export
const
fetchMeHandsMeta
=
createAsyncThunk
(
"
duel/fetchMeHandsMeta
"
,
async
(
Ids
:
number
[])
=>
{
return
await
Promise
.
all
(
Ids
.
map
(
async
(
id
)
=>
{
return
await
fetchCard
(
id
);
})
);
}
);
export
const
meHandsCase
=
(
builder
:
ActionReducerMapBuilder
<
DuelState
>
)
=>
{
builder
.
addCase
(
fetchMeHandsMeta
.
fulfilled
,
(
state
,
action
)
=>
{
// TODO: 合法性校验
const
cards
=
action
.
payload
;
if
(
state
.
meHands
)
{
state
.
meHands
.
cards
=
cards
;
}
else
{
state
.
meHands
=
{
cards
};
}
});
};
export
const
selectMeHands
=
(
state
:
RootState
)
=>
export
const
selectMeHands
=
(
state
:
RootState
)
=>
state
.
duel
.
meHands
||
{
cards
:
[]
};
state
.
duel
.
meHands
||
{
cards
:
[]
};
export
const
selectOpHands
=
(
state
:
RootState
)
=>
export
const
selectOpHands
=
(
state
:
RootState
)
=>
...
...
src/reducers/duel/mod.ts
View file @
a2b4da13
...
@@ -5,7 +5,12 @@
...
@@ -5,7 +5,12 @@
import
{
createSlice
}
from
"
@reduxjs/toolkit
"
;
import
{
createSlice
}
from
"
@reduxjs/toolkit
"
;
import
{
InitInfo
,
meInfoInitImpl
,
opInfoInitImpl
}
from
"
./initInfoSlice
"
;
import
{
InitInfo
,
meInfoInitImpl
,
opInfoInitImpl
}
from
"
./initInfoSlice
"
;
import
{
Hands
,
meAddHandsImpl
,
opAddHandsImpl
}
from
"
./handsSlice
"
;
import
{
Hands
,
meAddHandsImpl
,
opAddHandsImpl
,
meHandsCase
,
}
from
"
./handsSlice
"
;
import
{
RootState
}
from
"
../../store
"
;
import
{
RootState
}
from
"
../../store
"
;
export
interface
DuelState
{
export
interface
DuelState
{
...
@@ -26,6 +31,9 @@ const duelSlice = createSlice({
...
@@ -26,6 +31,9 @@ const duelSlice = createSlice({
meAddHands
:
meAddHandsImpl
,
meAddHands
:
meAddHandsImpl
,
opAddHands
:
opAddHandsImpl
,
opAddHands
:
opAddHandsImpl
,
},
},
extraReducers
(
builder
)
{
meHandsCase
(
builder
);
},
});
});
export
const
{
meInfoInit
,
opInfoInit
,
meAddHands
,
opAddHands
}
=
export
const
{
meInfoInit
,
opInfoInit
,
meAddHands
,
opAddHands
}
=
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment