-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add theme, router and current product, React Hooks and HOC to easily access the appropriate data #616
Merged
fkloes
merged 14 commits into
v6.X
from
PWA-1618-Provide-simple-custom-page-route-helper
Apr 12, 2019
Merged
Add theme, router and current product, React Hooks and HOC to easily access the appropriate data #616
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fa7da67
PWA-1618 Implemented react hook for custom routes.
devbucket ffdd4c7
PWA-1618 Implemented hoc
devbucket 31f0910
Merge branch 'v6.X' into PWA-1618-Provide-simple-custom-page-route-he…
devbucket 6d929fc
Merge branch 'v6.X' into PWA-1618-Provide-simple-custom-page-route-he…
devbucket d21b62c
PWA-1618 Fixed the engage package versioning.
devbucket 3c0b08b
PWA-1618 Removed the test component.
devbucket 2205511
PWA-1618 Added hooks and HOCs to easily access Theme, Route and Produ…
devbucket 8667432
PWA-1618 Renamed product helpers to *CurrentProduct.
devbucket 8b280a4
PWA-1618 Fixed unit tests.
devbucket 10522ae
Merge branch 'v6.X' of github.com:shopgate/pwa into PWA-1618-Provide-…
fkloes 232600e
PWA-1618 Updated engage package versions
fkloes f3f5c0c
Merge branch 'v6.X' into PWA-1618-Provide-simple-custom-page-route-he…
devbucket 5f20006
PWA-1618 Reverted commented out code.
devbucket 00d8727
Merge branch 'v6.X' into PWA-1618-Provide-simple-custom-page-route-he…
devbucket File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import { ThemeContext } from '@shopgate/pwa-common/context'; | ||
|
||
/** | ||
* Injects the current Product Context information into the desired component. | ||
* @param {Function} WrappedComponent The react component to wrap. | ||
* @returns {JSX} | ||
*/ | ||
export function withCurrentProduct(WrappedComponent) { | ||
return props => ( | ||
<ThemeContext.Consumer> | ||
{({ contexts: { ProductContext } }) => ( | ||
<ProductContext.Consumer> | ||
{productProps => <WrappedComponent {...productProps} {...props} />} | ||
</ProductContext.Consumer> | ||
)} | ||
</ThemeContext.Consumer> | ||
); | ||
} |
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,17 @@ | ||
import React from 'react'; | ||
import { RouteContext } from '@shopgate/pwa-common/context'; | ||
|
||
/** | ||
* Injects the route properties into the desired component. | ||
* @param {Function} WrappedComponent The react component to wrap. | ||
* @returns {JSX} | ||
*/ | ||
export function withRoute(WrappedComponent) { | ||
return props => ( | ||
<RouteContext.Consumer> | ||
{routeContext => ( | ||
<WrappedComponent {...routeContext} {...props} /> | ||
)} | ||
</RouteContext.Consumer> | ||
); | ||
} |
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,17 @@ | ||
import React from 'react'; | ||
import { ThemeContext } from '@shopgate/pwa-common/context'; | ||
|
||
/** | ||
* Injects the theme API into the desired component. This does not include the contexts. | ||
* @param {Function} WrappedComponent The react component to wrap. | ||
* @returns {JSX} | ||
*/ | ||
export function withTheme(WrappedComponent) { | ||
return props => ( | ||
<ThemeContext.Consumer> | ||
{({ contexts, ...themeContext }) => ( // The contexts are left out in favor of other HOCs. | ||
<WrappedComponent {...themeContext} {...props} /> | ||
)} | ||
</ThemeContext.Consumer> | ||
); | ||
} |
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,13 @@ | ||
import { useContext } from 'react'; | ||
import { ThemeContext } from '@shopgate/pwa-common/context'; | ||
|
||
/** | ||
* Provides the current product context props. | ||
* @returns {Object} | ||
*/ | ||
export function useCurrentProduct() { | ||
// The contexts are left out in favor of other hooks. | ||
const { contexts: { ProductContext } } = useContext(ThemeContext); | ||
const productProps = useContext(ProductContext); | ||
return productProps; | ||
} |
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,11 @@ | ||
import { useContext } from 'react'; | ||
import { RouteContext } from '@shopgate/pwa-common/context'; | ||
|
||
/** | ||
* Provides the route parameters. | ||
* @returns {Object} | ||
*/ | ||
export function useRoute() { | ||
const routeContext = useContext(RouteContext); | ||
return routeContext; | ||
} |
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,12 @@ | ||
import { useContext } from 'react'; | ||
import { ThemeContext } from '@shopgate/pwa-common/context'; | ||
|
||
/** | ||
* Provides the theme API. This does not include the contexts. | ||
* @returns {Object} | ||
*/ | ||
export function useTheme() { | ||
// The contexts are left out in favor of other hooks. | ||
const { contexts, ...themeContext } = useContext(ThemeContext); | ||
return themeContext; | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you replace this line by commented out code? Is it just because externals are now supposed to use the hooks / HOC?
In the recently updated DevDocs we have some articles where
import { Theme } from '@shopgate/engage/core';
is used within code snippets. This will not work anymore when the export is gone. So you also need to update the developer center articles with the new patterns from this PR.