-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
90 additions
and
63 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
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,17 +1,11 @@ | ||
const REGISTER_HOST_ACTION = 'REGISTER_HOST_ACTION'; | ||
const DEREGISTER_HOST_ACTION = 'DEREGISTER_HOST_ACTION'; | ||
|
||
const ADD_PORTAL_ACTION = 'ADD_PORTAL_ACTION'; | ||
const UPDATE_PORTAL_ACTION = 'UPDATE_PORTAL_ACTION'; | ||
const REMOVE_PORTAL_ACTION = 'REMOVE_PORTAL_ACTION'; | ||
enum ACTIONS { | ||
REGISTER_HOST, | ||
DEREGISTER_HOST, | ||
ADD_PORTAL, | ||
UPDATE_PORTAL, | ||
REMOVE_PORTAL, | ||
} | ||
|
||
const INITIAL_STATE = {}; | ||
|
||
export { | ||
REGISTER_HOST_ACTION, | ||
DEREGISTER_HOST_ACTION, | ||
ADD_PORTAL_ACTION, | ||
UPDATE_PORTAL_ACTION, | ||
REMOVE_PORTAL_ACTION, | ||
INITIAL_STATE, | ||
}; | ||
export { ACTIONS, INITIAL_STATE }; |
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 @@ | ||
export { reducer } from './reducer'; | ||
export * from './constants'; | ||
export { ACTIONS, INITIAL_STATE } from './constants'; | ||
export type { ActionTypes } from './types'; |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
interface PrintOptions { | ||
component?: string; | ||
method?: string; | ||
params?: Record<string, any> | string | number | boolean; | ||
} | ||
|
||
type Print = (options: PrintOptions) => void; | ||
|
||
let isLoggingEnabled = false; | ||
|
||
const enableLogging = () => { | ||
if (!__DEV__) { | ||
console.warn('[Portal] could not enable logging on production!'); | ||
return; | ||
} | ||
isLoggingEnabled = true; | ||
}; | ||
|
||
let print: Print = () => {}; | ||
|
||
if (__DEV__) { | ||
print = ({ component, method, params }) => { | ||
if (!isLoggingEnabled) { | ||
return; | ||
} | ||
let message = ''; | ||
|
||
if (typeof params === 'object') { | ||
message = Object.keys(params) | ||
.map(key => `${key}:${params[key]}`) | ||
.join(' '); | ||
} else { | ||
message = `${params ?? ''}`; | ||
} | ||
// eslint-disable-next-line no-console | ||
console.log( | ||
`[Portal::${[component, method].filter(Boolean).join('::')}]`, | ||
message | ||
); | ||
}; | ||
} | ||
|
||
Object.freeze(print); | ||
|
||
export { print, enableLogging }; |