Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
2236a1a3
Commit
2236a1a3
authored
Jan 30, 2019
by
Hugo Häggmark
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor change to Action interfaces
parent
94ce065f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
15 deletions
+15
-15
public/app/core/redux/actionCreatorFactory.ts
+6
-6
public/app/core/redux/reducerFactory.test.ts
+3
-3
public/app/core/redux/reducerFactory.ts
+6
-6
No files found.
public/app/core/redux/actionCreatorFactory.ts
View file @
2236a1a3
...
...
@@ -2,23 +2,23 @@ import { Action } from 'redux';
const
allActionCreators
:
string
[]
=
[];
export
interface
GrafanaAction
<
Payload
>
extends
Action
{
export
interface
ActionOf
<
Payload
>
extends
Action
{
readonly
type
:
string
;
readonly
payload
:
Payload
;
}
export
interface
Grafana
ActionCreator
<
Payload
>
{
export
interface
ActionCreator
<
Payload
>
{
readonly
type
:
string
;
(
payload
:
Payload
):
GrafanaAction
<
Payload
>
;
(
payload
:
Payload
):
ActionOf
<
Payload
>
;
}
export
interface
ActionCreatorFactory
<
Payload
>
{
create
:
()
=>
Grafana
ActionCreator
<
Payload
>
;
create
:
()
=>
ActionCreator
<
Payload
>
;
}
export
const
actionCreatorFactory
=
<
Payload
>
(
type
:
string
):
ActionCreatorFactory
<
Payload
>
=>
{
const
create
=
():
Grafana
ActionCreator
<
Payload
>
=>
{
return
Object
.
assign
((
payload
:
Payload
):
GrafanaAction
<
Payload
>
=>
({
type
,
payload
}),
{
type
});
const
create
=
():
ActionCreator
<
Payload
>
=>
{
return
Object
.
assign
((
payload
:
Payload
):
ActionOf
<
Payload
>
=>
({
type
,
payload
}),
{
type
});
};
if
(
allActionCreators
.
some
(
t
=>
(
t
&&
type
?
t
.
toLocaleUpperCase
()
===
type
.
toLocaleUpperCase
()
:
false
)))
{
...
...
public/app/core/redux/reducerFactory.test.ts
View file @
2236a1a3
import
{
reducerFactory
}
from
'./reducerFactory'
;
import
{
actionCreatorFactory
,
GrafanaAction
}
from
'./actionCreatorFactory'
;
import
{
actionCreatorFactory
,
ActionOf
}
from
'./actionCreatorFactory'
;
interface
DummyReducerState
{
n
:
number
;
...
...
@@ -37,7 +37,7 @@ describe('reducerFactory', () => {
describe
(
'when reducer is called with no state'
,
()
=>
{
describe
(
'and with an action that the handler can not handle'
,
()
=>
{
it
(
'then the resulting state should be intial state'
,
()
=>
{
const
result
=
dummyReducer
(
undefined
as
DummyReducerState
,
{}
as
GrafanaAction
<
any
>
);
const
result
=
dummyReducer
(
undefined
as
DummyReducerState
,
{}
as
ActionOf
<
any
>
);
expect
(
result
).
toEqual
(
dummyReducerIntialState
);
});
...
...
@@ -56,7 +56,7 @@ describe('reducerFactory', () => {
describe
(
'when reducer is called with a state'
,
()
=>
{
describe
(
'and with an action that the handler can not handle'
,
()
=>
{
it
(
'then the resulting state should be intial state'
,
()
=>
{
const
result
=
dummyReducer
(
dummyReducerIntialState
,
{}
as
GrafanaAction
<
any
>
);
const
result
=
dummyReducer
(
dummyReducerIntialState
,
{}
as
ActionOf
<
any
>
);
expect
(
result
).
toEqual
(
dummyReducerIntialState
);
});
...
...
public/app/core/redux/reducerFactory.ts
View file @
2236a1a3
import
{
GrafanaAction
,
Grafana
ActionCreator
}
from
'./actionCreatorFactory'
;
import
{
ActionOf
,
ActionCreator
}
from
'./actionCreatorFactory'
;
import
{
Reducer
}
from
'redux'
;
export
interface
HandlerConfig
<
State
,
Payload
>
{
filter
:
Grafana
ActionCreator
<
Payload
>
;
handler
:
(
state
:
State
,
action
:
GrafanaAction
<
Payload
>
)
=>
State
;
filter
:
ActionCreator
<
Payload
>
;
handler
:
(
state
:
State
,
action
:
ActionOf
<
Payload
>
)
=>
State
;
}
export
interface
AddHandler
<
State
>
{
...
...
@@ -11,7 +11,7 @@ export interface AddHandler<State> {
}
export
interface
CreateReducer
<
State
>
extends
AddHandler
<
State
>
{
create
:
()
=>
Reducer
<
State
,
GrafanaAction
<
any
>>
;
create
:
()
=>
Reducer
<
State
,
ActionOf
<
any
>>
;
}
export
const
reducerFactory
=
<
State
>
(
initialState
:
State
):
AddHandler
<
State
>
=>
{
...
...
@@ -27,8 +27,8 @@ export const reducerFactory = <State>(initialState: State): AddHandler<State> =>
return
instance
;
};
const
create
=
():
Reducer
<
State
,
GrafanaAction
<
any
>>
=>
{
const
reducer
:
Reducer
<
State
,
GrafanaAction
<
any
>>
=
(
state
:
State
=
initialState
,
action
:
GrafanaAction
<
any
>
)
=>
{
const
create
=
():
Reducer
<
State
,
ActionOf
<
any
>>
=>
{
const
reducer
:
Reducer
<
State
,
ActionOf
<
any
>>
=
(
state
:
State
=
initialState
,
action
:
ActionOf
<
any
>
)
=>
{
const
validHandlers
=
allHandlerConfigs
.
filter
(
config
=>
config
.
filter
.
type
===
action
.
type
)
.
map
(
config
=>
config
.
handler
);
...
...
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