-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from szhsin/feat/devtools-merged
feat: devtools merged
- Loading branch information
Showing
18 changed files
with
181 additions
and
85 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
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,7 +1,9 @@ | ||
import { useSyncExternalStore } from 'use-sync-external-store/shim'; | ||
|
||
var useSnapshot = function useSnapshot(state) { | ||
return useSyncExternalStore(state.subscribe, state.get, state.get); | ||
var useSnapshot = function useSnapshot(_ref) { | ||
var subscribe = _ref.subscribe, | ||
get = _ref.get; | ||
return useSyncExternalStore(subscribe, get, get); | ||
}; | ||
|
||
export { useSnapshot }; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,26 @@ | ||
var reduxDevtools = function reduxDevtools(_ref, config) { | ||
var get = _ref.get, | ||
subscribe = _ref.subscribe; | ||
if (typeof window === 'undefined' || !window.__REDUX_DEVTOOLS_EXTENSION__) return; | ||
var devtools = window.__REDUX_DEVTOOLS_EXTENSION__.connect({ | ||
name: config == null ? void 0 : config.key | ||
}); | ||
devtools.init(get()); | ||
subscribe(function () { | ||
return devtools.init(get()); | ||
var reduxDevtools = function reduxDevtools(_temp) { | ||
var _ref = _temp === void 0 ? {} : _temp, | ||
name = _ref.name; | ||
var devtoolsExt; | ||
if (typeof window === 'undefined' || !(devtoolsExt = window.__REDUX_DEVTOOLS_EXTENSION__)) return function () { | ||
/*do nothing*/ | ||
}; | ||
var devtools = devtoolsExt.connect({ | ||
name: name | ||
}); | ||
var mergedState = {}; | ||
return function (_ref2, config) { | ||
var get = _ref2.get, | ||
subscribe = _ref2.subscribe; | ||
var key = config == null ? void 0 : config.key; | ||
if (!key) throw new Error('[reactish-state] state should be provided with a string `key` in the config object when the `reduxDevtools` plugin is used.'); | ||
var updateState = function updateState() { | ||
mergedState[key] = get(); | ||
devtools.init(mergedState); | ||
}; | ||
updateState(); | ||
subscribe(updateState); | ||
}; | ||
}; | ||
|
||
export { reduxDevtools }; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,33 @@ | ||
import type {} from '@redux-devtools/extension'; | ||
import type { Plugin } from '../common'; | ||
|
||
const reduxDevtools: Plugin = ({ get, subscribe }, config) => { | ||
if (typeof window === 'undefined' || !window.__REDUX_DEVTOOLS_EXTENSION__) return; | ||
type ReduxDevtools = (options?: { name?: string }) => Plugin; | ||
|
||
const devtools = window.__REDUX_DEVTOOLS_EXTENSION__.connect({ name: config?.key }); | ||
devtools.init(get()); | ||
subscribe(() => devtools.init(get())); | ||
const reduxDevtools: ReduxDevtools = ({ name } = {}) => { | ||
let devtoolsExt: Window['__REDUX_DEVTOOLS_EXTENSION__']; | ||
if (typeof window === 'undefined' || !(devtoolsExt = window.__REDUX_DEVTOOLS_EXTENSION__)) | ||
return () => { | ||
/*do nothing*/ | ||
}; | ||
|
||
const devtools = devtoolsExt.connect({ name }); | ||
const mergedState: { [index: string]: unknown } = {}; | ||
|
||
return ({ get, subscribe }, config) => { | ||
const key = config?.key; | ||
if (!key) | ||
throw new Error( | ||
'[reactish-state] state should be provided with a string `key` in the config object when the `reduxDevtools` plugin is used.' | ||
); | ||
|
||
const updateState = () => { | ||
mergedState[key] = get(); | ||
devtools.init(mergedState); | ||
}; | ||
|
||
updateState(); | ||
subscribe(updateState); | ||
}; | ||
}; | ||
|
||
export { reduxDevtools }; |
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,7 +1,7 @@ | ||
import type { Reactish } from '../common'; | ||
import { useSyncExternalStore } from 'use-sync-external-store/shim'; | ||
|
||
const useSnapshot = <T>(state: Reactish<T>) => | ||
useSyncExternalStore<T>(state.subscribe, state.get, state.get); | ||
const useSnapshot = <T>({ subscribe, get }: Reactish<T>) => | ||
useSyncExternalStore<T>(subscribe, get, get); | ||
|
||
export { useSnapshot }; |
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,6 @@ | ||
import type { Middleware } from '../common'; | ||
declare const reduxDevtools: Middleware; | ||
declare type ReduxDevtools = (options?: { | ||
name?: string; | ||
}) => Middleware; | ||
declare const reduxDevtools: ReduxDevtools; | ||
export { reduxDevtools }; |
Oops, something went wrong.