forked from rtk-incubator/rtk-query
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Rename examples, small cleanup for brevity, show loading highlights in examples * Add global and app toggle examples * Make the svelte example a little more fun (or spooky! 👻 ) * Turn on/off polling copy in Svelte example
- Loading branch information
1 parent
bd116d2
commit 547c49b
Showing
61 changed files
with
450 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"sandboxes": ["new", "react-ts", "/examples/posts-and-counter", "/examples/svelte-counter"] | ||
"sandboxes": ["new", "react-ts", "/examples/react", "/examples/svelte"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
68 changes: 28 additions & 40 deletions
68
...unter/src/features/posts/PostsManager.css → examples/react/src/App.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,28 @@ | ||
.row { | ||
display: flex; | ||
flex-direction: row; | ||
flex-wrap: wrap; | ||
width: 100%; | ||
} | ||
|
||
.posts-list { | ||
display: flex; | ||
flex-direction: column; | ||
flex-basis: 100%; | ||
flex: 1; | ||
min-height: 200px; | ||
border-right: 1px solid #eee; | ||
padding: 20px; | ||
text-align: left; | ||
} | ||
|
||
.column { | ||
display: flex; | ||
flex-direction: column; | ||
flex-basis: 100%; | ||
flex: 3; | ||
} | ||
|
||
.column-3 { | ||
flex: 3; | ||
} | ||
|
||
.column-1 { | ||
flex: 1; | ||
} | ||
|
||
.column-2 { | ||
flex: 2; | ||
} | ||
|
||
.text-left { | ||
text-align: left; | ||
} | ||
.row { | ||
display: flex; | ||
flex-wrap: wrap; | ||
width: 100%; | ||
} | ||
|
||
.column { | ||
display: flex; | ||
flex-direction: column; | ||
flex-basis: 100%; | ||
flex: 3; | ||
} | ||
|
||
.column-3 { | ||
flex: 3; | ||
} | ||
|
||
.column-1 { | ||
flex: 1; | ||
} | ||
|
||
.column-2 { | ||
flex: 2; | ||
} | ||
|
||
.text-left { | ||
text-align: left; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react'; | ||
import { useAppDispatch, useTypedSelector } from '../../app/store'; | ||
import { | ||
selectGlobalPollingEnabled, | ||
selectPollingConfigByApp, | ||
toggleGlobalPolling, | ||
updatePolling, | ||
} from './pollingSlice'; | ||
|
||
const PollingToggleButton = ({ | ||
enabled, | ||
onClick, | ||
children, | ||
}: { | ||
onClick: () => void; | ||
enabled: boolean; | ||
children?: React.ReactNode; | ||
}) => { | ||
return ( | ||
<button onClick={onClick} style={enabled ? { background: 'lightgreen' } : {}}> | ||
{children} | ||
</button> | ||
); | ||
}; | ||
|
||
export const PollingToggles = () => { | ||
const dispatch = useAppDispatch(); | ||
const globalPolling = useTypedSelector(selectGlobalPollingEnabled); | ||
const timesPolling = useTypedSelector((state) => selectPollingConfigByApp(state, 'times')); | ||
|
||
return ( | ||
<div> | ||
<small>Global Polling Configs</small> | ||
<div> | ||
<PollingToggleButton enabled={globalPolling} onClick={() => dispatch(toggleGlobalPolling())}> | ||
Global | ||
</PollingToggleButton> | ||
<PollingToggleButton | ||
enabled={timesPolling.enabled} | ||
onClick={() => dispatch(updatePolling({ app: 'times', enabled: !timesPolling.enabled }))} | ||
> | ||
Times | ||
</PollingToggleButton> | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'; | ||
import { RootState } from '../../app/store'; | ||
|
||
type PollingConfig = { | ||
enabled: boolean; | ||
interval: number; | ||
}; | ||
|
||
type SliceState = { | ||
enabled: boolean; | ||
apps: { | ||
[key: string]: PollingConfig; | ||
}; | ||
}; | ||
|
||
const initialState: SliceState = { | ||
enabled: true, | ||
apps: { | ||
counters: { | ||
enabled: true, | ||
interval: 0, | ||
}, | ||
times: { | ||
enabled: true, | ||
interval: 0, | ||
}, | ||
posts: { | ||
enabled: true, | ||
interval: 0, | ||
}, | ||
}, | ||
}; | ||
|
||
type PollingAppKey = keyof typeof initialState['apps']; | ||
|
||
const slice = createSlice({ | ||
name: 'polling', | ||
initialState, | ||
reducers: { | ||
toggleGlobalPolling(state) { | ||
state.enabled = !state.enabled; | ||
}, | ||
updatePolling( | ||
state, | ||
{ | ||
payload, | ||
}: PayloadAction<{ | ||
app: PollingAppKey; | ||
enabled?: boolean; | ||
interval?: number; | ||
}> | ||
) { | ||
const { app, ...rest } = payload; | ||
state.apps[app] = { | ||
...state.apps[app], | ||
...rest, | ||
}; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { toggleGlobalPolling, updatePolling } = slice.actions; | ||
|
||
export default slice.reducer; | ||
|
||
export const selectGlobalPollingEnabled = (state: RootState) => state.polling.enabled; | ||
export const selectPollingConfigByApp = (state: RootState, app: PollingAppKey) => state.polling.apps[app]; |
File renamed without changes.
Oops, something went wrong.