Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
7c13e7ad
Commit
7c13e7ad
authored
Mar 26, 2022
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing types to toastMessages store module
parent
38a7e84a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
14 deletions
+24
-14
toast-messages.js
src/sidebar/store/modules/toast-messages.js
+24
-14
No files found.
src/sidebar/store/modules/toast-messages.js
View file @
7c13e7ad
import
{
createStoreModule
}
from
'../create-store'
;
import
*
as
util
from
'../util'
;
import
{
createStoreModule
,
makeAction
}
from
'../create-store'
;
/**
* @typedef ToastMessage
...
...
@@ -22,21 +20,35 @@ const initialState = {
messages
:
[],
};
/** @typedef {typeof initialState} State */
const
reducers
=
{
ADD_MESSAGE
:
function
(
state
,
action
)
{
/**
* @param {State} state
* @param {{ message: ToastMessage }} action
*/
ADD_MESSAGE
(
state
,
action
)
{
return
{
messages
:
state
.
messages
.
concat
({
...
action
.
message
}),
};
},
REMOVE_MESSAGE
:
function
(
state
,
action
)
{
/**
* @param {State} state
* @param {{ id: string }} action
*/
REMOVE_MESSAGE
(
state
,
action
)
{
const
updatedMessages
=
state
.
messages
.
filter
(
message
=>
message
.
id
!==
action
.
id
);
return
{
messages
:
updatedMessages
};
},
UPDATE_MESSAGE
:
function
(
state
,
action
)
{
/**
* @param {State} state
* @param {{ message: ToastMessage }} action
*/
UPDATE_MESSAGE
(
state
,
action
)
{
const
updatedMessages
=
state
.
messages
.
map
(
message
=>
{
if
(
message
.
id
&&
message
.
id
===
action
.
message
.
id
)
{
return
{
...
action
.
message
};
...
...
@@ -47,15 +59,13 @@ const reducers = {
},
};
const
actions
=
util
.
actionTypes
(
reducers
);
/** Actions */
/**
* @param {ToastMessage} message
*/
function
addMessage
(
message
)
{
return
{
type
:
actions
.
ADD_MESSAGE
,
message
}
;
return
makeAction
(
reducers
,
'ADD_MESSAGE'
,
{
message
})
;
}
/**
...
...
@@ -64,7 +74,7 @@ function addMessage(message) {
* @param {string} id
*/
function
removeMessage
(
id
)
{
return
{
type
:
actions
.
REMOVE_MESSAGE
,
id
}
;
return
makeAction
(
reducers
,
'REMOVE_MESSAGE'
,
{
id
})
;
}
/**
...
...
@@ -73,7 +83,7 @@ function removeMessage(id) {
* @param {ToastMessage} message
*/
function
updateMessage
(
message
)
{
return
{
type
:
actions
.
UPDATE_MESSAGE
,
message
}
;
return
makeAction
(
reducers
,
'UPDATE_MESSAGE'
,
{
message
})
;
}
/** Selectors */
...
...
@@ -81,8 +91,8 @@ function updateMessage(message) {
/**
* Retrieve a message by `id`
*
* @param {State} state
* @param {string} id
* @return {object|undefined}
*/
function
getMessage
(
state
,
id
)
{
return
state
.
messages
.
find
(
message
=>
message
.
id
===
id
);
...
...
@@ -91,7 +101,7 @@ function getMessage(state, id) {
/**
* Retrieve all current messages
*
* @
return {object[]}
* @
param {State} state
*/
function
getMessages
(
state
)
{
return
state
.
messages
;
...
...
@@ -102,9 +112,9 @@ function getMessages(state) {
* text exists in the state's collection of messages. This matches messages
* by content, not by ID (true uniqueness).
*
* @param {State} state
* @param {string} type
* @param {string} text
* @return {boolean}
*/
function
hasMessage
(
state
,
type
,
text
)
{
return
state
.
messages
.
some
(
message
=>
{
...
...
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