Skip to content

Commit

Permalink
added: highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor Pasynok committed Nov 5, 2024
1 parent 2642a31 commit 66b3469
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This feature is especially useful when troubleshooting dependencies and monitori

The `compose.up` function accepts an optional second argument, a configuration object, which can include `debug`. When `debug: true` is set, `compose.up` will output each container's status as it changes. Here’s how to enable debugging:

```ts
```ts {9}
import { createContainer, compose } from '@grlt-hub/app-compose';

const start: () => { api: {} };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ With these techniques, you can create asynchronous flows that allow containers t

For containers that need to perform asynchronous operations, `start` can be defined as an `async` function. Here’s an example where `start` fetches data from an API:

```ts
```ts {5}
import { createContainer, compose } from '@grlt-hub/app-compose';

const userContainer = createContainer({
Expand Down Expand Up @@ -46,7 +46,7 @@ User data loaded: { ... }
The `enable` function can also handle asynchronous conditions by returning a promise. This allows you to delay container initialization until specific conditions are met based on asynchronous checks.
```ts
```ts {5}
import { createContainer, compose } from '@grlt-hub/app-compose';
const restrictedFeatureContainer = createContainer({
Expand Down Expand Up @@ -84,7 +84,7 @@ If the `permissions` do not grant access, `restrictedFeatureContainer` will rema
When working with multiple containers, you might want to wait until all containers complete their `start` or `enable` tasks. Since `compose.up` returns a `promise`, you can `await` it to ensure that all containers have finished their initialization.
```ts
```ts {19}
const configContainer = createContainer({
id: 'config',
start: async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ To control execution order more precisely, you can create "priority" containers.

This approach is a trade-off: by using priority containers, you avoid linking each secondary feature to every high-priority container individually. This keeps the code cleaner and reduces unnecessary dependencies.

```ts
```ts {14,23}
const highPriorityFeatures = createContainer({
id: 'highPriority',
start: () => ({ api: {} }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ By using these parameters, you can conditionally access dependency data as neede

In this example, we set up two containers, where one (`accountContainer`) depends on the other (`userContainer`). The `accountContainer` will not start until the `userContainer` has successfully completed.

```ts
```ts {13}
import { createContainer, compose } from '@grlt-hub/app-compose';

const userContainer = createContainer({
Expand Down Expand Up @@ -93,7 +93,7 @@ Account loaded for user: user123

In this example, `notificationContainer` has an optional dependency on `userContainer`. If `userContainer` completes successfully, `notificationContainer` can access user data. If `userContainer` does not complete or is turned off, `notificationContainer` will still start but without user data.

```ts
```ts {3}
const notificationContainer = createContainer({
id: 'notification',
optionalDependsOn: [userContainer],
Expand Down Expand Up @@ -129,7 +129,7 @@ Notifications loaded without user context

In this example, `dashboardContainer` depends on `settingsContainer` as a strict dependency and on `userContainer` as an optional dependency. It will only start after `settingsContainer` completes but can use `userContainer` if available.

```ts
```ts {11-12}
const settingsContainer = createContainer({
id: 'settings',
start: () => {
Expand Down
6 changes: 3 additions & 3 deletions website/src/content/docs/how-to-guides/use-enable.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Using `enable` provides fine-grained control over the execution of containers ba

In this example, we’ll create a container that only starts if a certain condition is met. The `enable` function will check this condition and return `true` or `false`.

```ts
```ts {14}
import { createContainer, compose } from '@grlt-hub/app-compose';

const featureToggle = createContainer({
Expand Down Expand Up @@ -84,7 +84,7 @@ If `isEnabled` is `false`, then newFeature will remain `off` and not print anyth

This example demonstrates using an asynchronous `enable` to control execution based on a network request. The container will only start if the user has permissions loaded from an API.

```ts
```ts {15}
import { createContainer, compose } from '@grlt-hub/app-compose';

const userPermissions = createContainer({
Expand Down Expand Up @@ -166,7 +166,7 @@ Dashboard started

In this example, we’ll create a container that has an optional dependency and uses `enable` to check if the optional dependency is available before starting. The container will only start if the optional dependency provides the necessary data.

```ts
```ts {14}
import { createContainer, compose } from '@grlt-hub/app-compose';

const optionalFeature = createContainer({
Expand Down
6 changes: 3 additions & 3 deletions website/src/content/docs/how-to-guides/use-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Using `start` effectively allows containers to initialize with necessary data an

For simple tasks that don’t involve asynchronous operations, `start` can be used synchronously. Here’s an example of a container that initializes with basic configuration data:

```ts
```ts {5}
import { createContainer, compose } from '@grlt-hub/app-compose';

const configContainer = createContainer({
Expand All @@ -45,7 +45,7 @@ Configuration loaded

If `start` needs to perform asynchronous tasks, such as fetching data from an API, you can make it asynchronous by defining it as an `async` function. Here’s an example:

```ts
```ts {5}
import { createContainer, compose } from '@grlt-hub/app-compose';

const dataContainer = createContainer({
Expand Down Expand Up @@ -73,7 +73,7 @@ Data loaded: { ... }
The `start` function should always return an object with an `api` key, which provides data or functions that might be needed elsewhere in the application. Here’s an example of how to structure this return value:
```ts
```ts {4}
const settingsContainer = createContainer({
id: 'settings',
start: () => {
Expand Down

0 comments on commit 66b3469

Please sign in to comment.