-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: one context to rule them all
- Loading branch information
Showing
11 changed files
with
100 additions
and
32 deletions.
There are no files selected for viewing
11 changes: 0 additions & 11 deletions
11
dotcom-rendering/.storybook/decorators/RenderingTargetDecorator.js
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
dotcom-rendering/.storybook/decorators/renderingContextDecorator.js
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,19 @@ | ||
import { RenderingContext } from '../../src/components/RenderingContext'; | ||
|
||
const defaultContext = { target: 'Web' }; | ||
|
||
export const RenderingContextDecorator = ( | ||
Story, | ||
{ args: { renderingContext } }, | ||
) => { | ||
const context = { ...defaultContext, ...renderingContext }; | ||
|
||
// For easy debugging | ||
console.log('Storybook rendering context: \n', context); | ||
|
||
return ( | ||
<RenderingContext.Provider value={context}> | ||
<Story /> | ||
</RenderingContext.Provider> | ||
); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createContext } from 'react'; | ||
import type { RenderingContextType } from '../types/renderingContext'; | ||
|
||
/** Represents the initial or default value for the app context */ | ||
const defaultContext: RenderingContextType = { | ||
target: 'Web', | ||
}; | ||
|
||
/** | ||
* Context for global, static values (generic) | ||
* | ||
* This should not contain anything which will change between re-renders | ||
*/ | ||
export const RenderingContext = | ||
createContext<RenderingContextType>(defaultContext); |
This file was deleted.
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { RenderingTarget } from './renderingTarget'; | ||
|
||
/** | ||
* Context for global values (generic) | ||
* | ||
* This should not contain any properties which are likely to change between re-renders | ||
*/ | ||
export interface RenderingContextType { | ||
target: RenderingTarget; | ||
} |