diff --git a/docs/guides/product-context.md b/docs/guides/product-context.md index 85913dd5a0..b464d63640 100644 --- a/docs/guides/product-context.md +++ b/docs/guides/product-context.md @@ -11,28 +11,28 @@ Product Contexts were introduced in PWA version [0.27](https://github.com/inters ## What is a Product Context? -Product Contexts provide an easy access to all data related to a single product. -The context itself stores the `sku` and (optional) `quantity` of the product and delegates all other information from the [State Management][state-management] in a simplified fashion. +Product contexts provide easy access to all data related to a single product. +The context itself stores the `sku` and (optional) the `quantity` of the product and delegates all other information from the [State Management][state-management] in a simplified fashion. The following screenshots provide examples where product contexts are used on some pages:
-For product pages, there is always one context, that spans all the content of the product page. -Nevertheless additional contexts for recommended products or bundled products can exist on the page. +For product pages, there is always one context that spans the entire content of the product page. +However, additional contexts for recommended products or bundled products may exist on the page. For listings of any kind, individual contexts exist on the page for each product. Product Contexts can also be linked to their parent contexts. -## How to introduce Product Context? +## How to Introduce Product Context? -Other than normal facades, which are globally available and only one instance is available at runtime, context facades are provided using [`ElementInjector`](https://angular.io/guide/hierarchical-dependency-injection#elementinjector) and are therefore only available for elements enclosed in the document subtree, for which element introduced the context. +Unlike regular facades, which are available globally and have only one instance available at runtime, context facades are provided using [`ElementInjector`](https://angular.io/guide/hierarchical-dependency-injection#elementinjector) and are therefore only available for elements enclosed in the document subtree for which the element introduced the context. -### by using [`ProductContextDirective`][src-product-context-directive] +### By Using [`ProductContextDirective`][src-product-context-directive] The easiest way to start a product context is by using the [`ProductContextDirective`][src-product-context-directive] on templates: @@ -46,21 +46,20 @@ The easiest way to start a product context is by using the [`ProductContextDirec What happens here? -- For each individual `item` from `lineItems$`, a product context is provided for embedded elements. +- For each individual `item` from `lineItems$`, a product context for embedded elements is provided. - Each individual context is associated with `item.sku` which also triggers fetching the product if it is not already available in the store. - The `ish-product-name` component will render the product name. This also portrays one of the main advantages of using this concept: No bubbling of product related data is necessary anymore. -The `ish-product-name` component is injecting the provided context and decides which data is used for rendering. +The `ish-product-name` component injects the provided context and decides which data is used for rendering. -Have a look at [`ProductDetailComponent`](../../src/app/pages/product/product-detail/product-detail.component.html), which now only does layout and styling, whereas the context is provided by the outer [`ProductPageComponent`][src-product-page-component-ts]. +Note: [`ProductDetailComponent`](../../src/app/pages/product/product-detail/product-detail.component.html) is only used for layout and styling, whereas the context is provided by the outer [`ProductPageComponent`][src-product-page-component-ts]. -### by providing [`ProductContextFacade`][src-product-context-facade] +### By Providing [`ProductContextFacade`][src-product-context-facade] -There are cases, where it is not possible to use the directive. -For example, if the parent component does not have access to all required information, or the component has to introduce another context by itself. +There are cases for which it is not possible to use the directive: For example, when the parent component does not have access to all required information or when the component has to introduce another context by itself. In this case the [`ProductContextFacade`][src-product-context-facade] has to be added to the `providers` array of the [`@Component`](https://angular.io/api/core/Component) decorator. -Afterwards, the sku for the context has to be initialized: +Afterwards, the SKU for the context has to be initialized: ```typescript @Component({ @@ -78,18 +77,18 @@ export class MyComponent implements OnInit { } ``` -### by providing [`SelectedProductContextFacade`][src-selected-product-context-facade] +### By Providing [`SelectedProductContextFacade`][src-selected-product-context-facade] -For pages, that are using the `:sku` route parameter, the Product Context can be introduced on the page level by using [`SelectedProductContextFacade`][src-selected-product-context-facade]. +For pages that use the `:sku` route parameter, the product context can be introduced on page level by using [`SelectedProductContextFacade`][src-selected-product-context-facade]. Have a look at [`ProductPageComponent`][src-product-page-component-ts] for an example. ## Retrieving Data from the Product Context -### inject [`ProductContextFacade`][src-product-context-facade] +### Inject [`ProductContextFacade`][src-product-context-facade] -The easiest way to interact with the context is by doing the same you would do with facades. -Inject the [`ProductContextFacade`][src-product-context-facade] into your components and relay data for the template into Observables and use the [async pipe](https://angular.io/guide/observables-in-angular#async-pipe) there: +The easiest way to interact with the context is to do the same as you would do with facades. +Inject the [`ProductContextFacade`][src-product-context-facade] into your components and relay data for the template into observables and use the [async pipe](https://angular.io/guide/observables-in-angular#async-pipe) there: ```typescript @Component({ ... }) @@ -112,9 +111,9 @@ export class MyComponent implements OnInit {