Skip to content

Commit

Permalink
docs(cart): clean up verbiage according to documentation guidelines (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
xelaint authored Aug 19, 2024
1 parent d945df3 commit f063c7d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
8 changes: 4 additions & 4 deletions libs/cart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Building and maintaining a model and code for an ecommerce store is complex and
provides clear interfaces, models, and factories for the frontend of an ecommerce store so that you don't have to.

## Installation
To install the cart library and its dependencies, use the following commands in the terminal.
To install `@daffodil/cart` and its dependencies, use the following commands in the terminal.

Install with npm:
```
Expand All @@ -16,7 +16,7 @@ yarn add @daffodil/cart @daffodil/core @ngrx/store @ngrx/effects
```

## Getting started
The cart module includes multiple layers of functionality that build on each other. The models can be used on their own. The driver layers can be used with the models but also allow custom extensions to those models to be passed as generics. A state layer sits on top of the driver layer. Individual drivers can be overridden through driver injection tokens and custom extensions to models can be passed into the state layer's generics.
`@daffodil/cart` includes multiple layers of functionality that build on each other. The models can be used on their own. The driver layers can be used with the models but also allow custom extensions to those models to be passed as generics. A state layer sits on top of the driver layer. Individual drivers can be overridden through driver injection tokens and custom extensions to models can be passed into the state layer's generics.

The recommended way to use Daffodil is with the state layer.

Expand All @@ -32,7 +32,7 @@ Interacting with platforms through the [cart facade](/libs/cart/guides/state.md#
It is possible to interact with platforms by directly calling the drivers. While this requires more work to integrate into components, it offers greater flexibility. See the [drivers guide](/libs/cart/guides/drivers.md) for more information.

### Using routing guards
The cart module provides a number of routing guards to prevent access to certain pages until specific data becomes available.
`@daffodil/cart` provides a number of routing guards to prevent access to certain pages until specific data becomes available.

The following example illustrates using the `DaffShippingAddressGuard` to prevent accessing the shipping method page of checkout until a shipping address has been set.

Expand Down Expand Up @@ -70,7 +70,7 @@ class AppModule {}
> The `'checkout/shipping'` route's activation was guarded with the `DaffShippingAddressGuard`, ensuring that page cannot be accessed unless the cart has a valid shipping address set. The `DaffCartShippingAddressGuardRedirectUrl` token is used to configure the path to which the user is redirected when and if the activation fails.
### Providing platform-agnostic payment IDs
The cart facade provides a field (`paymentId$`) for agnostic payment IDs. The IDs must be user-supplied to prevent circular package dependencies. Provide an object for the `DaffCartPaymentMethodIdMap` token. The keys of this object should be cart payment methods and the values should be strings.
`DaffCartFacade` provides a field (`paymentId$`) for agnostic payment IDs. The IDs must be user-supplied to prevent circular package dependencies. Provide an object for the `DaffCartPaymentMethodIdMap` token. The keys of this object should be cart payment methods and the values should be strings.

```ts
import {
Expand Down
26 changes: 14 additions & 12 deletions libs/cart/guides/drivers.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Drivers
The cart module can interface with supported platforms through drivers. Choose the driver that corresponds to the platform of choice and follow the linked guide to set it up.
`@daffodil/cart` can interface with supported platforms through drivers. Choose the driver that corresponds to the platform of choice and follow the linked guide to set it up.

## Supported drivers

### In-Memory web API
The In-Memory driver is for rapid development without the need to set up a magento/shopify/etc backend. It will mock out the management of a cart and operate like a functional backend. It is intended for development and testing purposes and not meant to be used in production.
### In-memory web API
The in-memory driver is for rapid development without the need to set up a magento/shopify/etc backend. It will mock out the management of a cart and operate like a functional backend. It is intended for development and testing purposes and not meant to be used in production.

To set up, import the `DaffCartInMemoryDriverModule` from the `@daffodil/cart/testing` library and the `HttpClientInMemoryWebApiModule` from `angular-in-memory-web-api`.

Include `DaffCartInMemoryDriverModule.forRoot()` and `HttpClientInMemoryWebApiModule` in the imports section of `AppModule`.
To set up in the root component:
1. Import the `DaffCartInMemoryDriverModule` from `@daffodil/cart/testing`
2. Import `HttpClientInMemoryWebApiModule` from `angular-in-memory-web-api`
3. Include `DaffCartInMemoryDriverModule.forRoot()` and `HttpClientInMemoryWebApiModule` in the imports section

```ts
import { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api';
Expand All @@ -23,16 +24,17 @@ import { DaffCartInMemoryDriverModule } from '@daffodil/cart/testing';
export class AppModule {}
```

Now this `DaffCart` implementation will have access to the In-Memory driver to use while developing.
Now this `DaffCart` implementation will have access to the in-memory driver to use while developing.

> Note: It is important to only have one `daffodil/cart` driver set up at a time in the `AppModule`. To set up a driver configuration to make switching between different backend drivers simple, follow the [advanced setup guide](). <!-- TODO: add multiple drivers guide -->
> Note: It is important to only have one `daffodil/cart` driver set up at a time in the root component. To set up a driver configuration to make switching between different backend drivers simple, follow the [advanced setup guide](). <!-- TODO: add multiple drivers guide -->
### Magento
The Magento driver communicates with the Magento backend through the GraphQL API.

To set up, import the `DaffCartMagentoDriverModule` from the `@daffodil/cart` library and the `ApolloModule` from `apollo-angular`.

Include `DaffCartMagentoDriverModule.forRoot()` and `ApolloModule` in the imports section of `AppModule`.
To set up in the root component:
1. Import the `DaffCartMagentoDriverModule` from `@daffodil/cart`
2. Import `ApolloModule` from `apollo-angular`
3. Include `DaffCartMagentoDriverModule.forRoot()` and `ApolloModule` in the imports section

```ts
import { ApolloModule } from 'apollo-angular';
Expand All @@ -49,7 +51,7 @@ export class AppModule {}

This `DaffCart` implementation will now be able to interact with Magento.

> Note: It is important to only have one `@daffodil/cart` driver set up in `AppModule` at a time. To set up a driver configuration to make switching between different backend drivers simple, follow the [advanced setup guide](). <!-- TODO: add multiple drivers guide -->
> Note: It is important to only have one `@daffodil/cart` driver set up in the root component at a time. To set up a driver configuration to make switching between different backend drivers simple, follow the [advanced setup guide](). <!-- TODO: add multiple drivers guide -->
#### Fragment introspection
You should set up fragment introspection with the Magento backend. Refer to the [fragment introspection guide](../../../../tools/builders/guides/fragment-introspection.md) for more information.
Expand Down
3 changes: 2 additions & 1 deletion libs/cart/guides/extension.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Extension
The cart module provides a number of extension mechanisms so that it can be customized to fit specific needs.
`@daffodil/cart` provides a number of extension mechanisms so that it can be customized to fit specific needs.

## Custom drivers
If the packaged Daffodil drivers don't satisfy the required use cases, they can be overriden by providing custom drivers. Create a service that implements the interface corresponding to the driver in question.
Expand All @@ -15,6 +15,7 @@ import {
@Injectable({
providedIn: 'root'
})

export class CustomMagentoCartService implements DaffCartServiceInterface {
constructor(
private cartDriver: DaffMagentoCartService,
Expand Down
9 changes: 5 additions & 4 deletions libs/cart/guides/state.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# State
The cart module provides a fully featured state library to streamline the management of an application's state as well as driver interaction. The facade is an abstraction that provides all the functionality needed for standard use. It is the recommended way to interact with the Daffodil state layer.
`@daffodil/cart` provides a fully featured state library to streamline the management of an application's state as well as driver interaction. The facade is an abstraction that provides all the functionality needed for standard use. It is the recommended way to interact with the Daffodil state layer.

## Setting up the root module
To get started, import the `DaffCartStateModule` in `AppModule`. Next, import `StoreModule.forRoot({})`, which will be relevant later on when using the redux and state management features of the cart module.
## Set up the root component
1. Import the `DaffCartStateModule`
2. Import `StoreModule.forRoot({})`, which will be relevant later on when using the redux and state management features `@daffodil/cart`.

```typescript
@ngModule({
Expand Down Expand Up @@ -205,7 +206,7 @@ If you need the guarantee, you can nest the guards.
```

## Configuration
The `@daffodil/cart/state` package exposes a `forRoot` method on the `DaffCartStateModule` that allows you to pass in a configuration object to configure the behavior of the package.
`@daffodil/cart/state` exposes a `forRoot` method on the `DaffCartStateModule` that allows you to pass in a configuration object to configure the behavior of the package.

You can import it like so:

Expand Down
2 changes: 1 addition & 1 deletion libs/cart/guides/testing.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Testing
The cart module provides a testing package accessible at `@daffodil/cart/testing`. This package provides model factories, facade mocks, and driver mocks to facilitate unit testing.
`@daffodil/cart` provides a testing package accessible at `@daffodil/cart/testing`. This package provides model factories, facade mocks, and driver mocks to facilitate unit testing.

## Example
The following example demonstrates how to unit test a component using Daffodil model factories and the mock facade with the Jasmine testing framework and the `jasmine-marbles` library.
Expand Down

0 comments on commit f063c7d

Please sign in to comment.