Skip to content

Commit 6850488

Browse files
committed
update component lifecycle
1 parent 4e395d7 commit 6850488

5 files changed

Lines changed: 21 additions & 16 deletions

File tree

‎docs/components/compositions/index.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Benefits of nesting include:
5353
When nesting components, consider the following:
5454

5555
- **Responsibility boundaries**: Each component should have a clear, focused responsibility
56-
- **Data flow**: Parent components pass data down to child components through [attributes](/components/interface-and-lifecycle#defining-attributes) or [contexts](/contexts/overview). Child components send data up to parents through [events](/components/interface-and-lifecycle#setting-up-events) or [contexts](/contexts/overview)
56+
- **Data flow**: Parent components pass data down to child components through [attributes](/components/interface-and-lifecycle#defining-attributes) or [contexts](/contexts/overview). Child components send data up to parents through [events](/components/interface-and-lifecycle#adding-events) or [contexts](/contexts/overview)
5757
- **Styling**: Parent components can [style the root element](/styling/conditional-styles#component-style-overrides) of nested components
5858

5959
::: tip

‎docs/components/interface-and-lifecycle/index.md‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
---
22
title: Interface and lifecycle
3-
description: Define component interfaces with attributes and events, and control behavior at initialization, update and removal phases in the component lifecycle.
3+
description: Define component interfaces with attributes and events, and control behavior in the component lifecycle.
44
---
55

66
# Interface and lifecycle
77

8-
Components in Nordcraft need clearly defined interfaces to interact with the rest of your website, and they follow a specific lifecycle as they are created, updated and removed from the page. Understanding component interfaces and lifecycle helps you create components that integrate seamlessly with the rest of your project and behave predictably as your website state changes.
8+
Components in Nordcraft have a data interface made up of attributes, events and contexts, and follow a specific lifecycle as they are created, updated and removed from the page.
99

1010
## Component interface
1111

12-
The interface of a component defines how it communicates with other parts of your website. There are three communication channels
12+
The interface of a component defines how it communicates with other parts of your website. There are three communication channels:
1313

1414
- [Attributes](#defining-attributes): Data flow into the component (input)
15-
- [Events](#setting-up-events): Data flow out to parent components (output)
15+
- [Events](#adding-events): Data flow out to parent components (output)
1616
- [Contexts](#data-flow-with-contexts): Data flow between parent and any descendant components
1717

1818
::: tip
@@ -48,14 +48,14 @@ For example, a **tooltip** component might use attributes to control:
4848
- Whether the tooltip has a close button
4949

5050
::: info
51-
Attributes can be accessed inside any formula within the component.
51+
You can access any defined component attributes inside any formula within the component.
5252
:::
5353

5454
::: info
55-
The test value is only used while developing your component in the editor. It has no impact on how your component will behave when used in other components or pages.
55+
The test value for component attributes is only used while editing your component in the editor. This test value has no impact on how your component will behave when used in other components or pages, or on your live website in production.
5656
:::
5757

58-
### Setting up events
58+
### Adding events
5959

6060
![An onClick event is defined in the events list in the right panel. The event dialog is open, showing a test value of an object representing a JavaScript event.|16/9](set-up-an-event.webp 'Set up an event'){https://editor.nordcraft.com/projects/docs_examples/branches/main/components/screenshot-card-container?canvas-width=800&rightpanel=style&selection=events.0&canvas-height=800}
6161

@@ -69,7 +69,7 @@ Events allow components to communicate upward to parent elements:
6969
Events enable child components to send messages and data up to their parent components.
7070

7171
::: info
72-
The test data is only used while developing your component. It helps when setting up workflows in parent components that will handle this event, but has no impact on your live website in preview or production.
72+
The test data is only used while editing your component. This test data has no impact on how your component will behave when used in other components or pages, or on your live website in production.
7373
:::
7474

7575
### Triggering events
@@ -87,12 +87,17 @@ Unlike HTML element events that trigger automatically on user interactions, comp
8787

8888
1. Click the `+` button to add a new action
8989
2. In **Events**, select the `Trigger: event` action for desired component event to trigger
90-
3. Define the data payload to send with the event
90+
3. Define the data to send with the event
9191

92-
::: info
93-
All events defined in a component appear under the **Events** section when setting up event handlers.
92+
::: tip
93+
For a demo of how to add and use component events, check out the following lesson from the [Nordcraft Fundamentals](https://nordcraft.com/learn/fundamentals) video course.
9494
:::
9595

96+
@@@ youtube
97+
videoId: gttYD_Aftc8
98+
title: Using component events
99+
@@@
100+
96101
## Data flow with contexts
97102

98103
In addition to attributes and events, components can communicate through contexts. Contexts provide an alternative communication channel that allows components to share data and functionality across the component tree without passing through intermediaries.
@@ -162,5 +167,5 @@ Components maintain their own internal state using [variables](/variables/overvi
162167
- Reset when the component is removed and added again
163168

164169
::: info
165-
When a component is unmounted, all its resources, including event listeners, workflows, and variable values, are automatically cleaned up. This helps prevent memory leaks in your website which may make it run more slowly or cause browser crashes.
170+
When a component is removed, all its resources, including event listeners, workflows, and variable values, are automatically cleaned up.
166171
:::

‎docs/components/overview/index.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ A component in Nordcraft can consist of:
5252
- [Attributes](/components/interface-and-lifecycle#defining-attributes): The interface for passing data into the component
5353
- [Variables](/variables/overview): Internal state and data management
5454
- [APIs](/connecting-data/overview): Connections to external services and data sources
55-
- [Events](/components/interface-and-lifecycle#setting-up-events): The interface for communicating out from the component
55+
- [Events](/components/interface-and-lifecycle#adding-events): The interface for communicating out from the component
5656
- [Formulas](/formulas/overview): Calculations and data transformations
5757
- [Workflows](/workflows/overview): Internal logic and behavior
5858
- [Contexts](/contexts/overview): Communication with ancestor and descendant components or elements

‎docs/contexts/overview/index.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Contexts in Nordcraft provide a way to share data and functionality between comp
1010
In traditional component architecture, data typically flows in two ways:
1111

1212
- **Downward**: From parent to child via [attributes](/components/interface-and-lifecycle#defining-attributes)
13-
- **Upward**: From child to parent via [events](/components/interface-and-lifecycle#setting-up-events)
13+
- **Upward**: From child to parent via [events](/components/interface-and-lifecycle#adding-events)
1414

1515
However, this approach can become unmanageable in complex component trees where data needs to flow through multiple levels. This can lead to "attribute drilling", which is where you pass data through intermediate components that don't need access to it, just to reach components deeper in the tree.
1616

‎docs/workflows/working-with-workflows/index.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Learn how to create event-triggered and reusable workflows with parameters and s
99

1010
## Create a workflow
1111

12-
You can create a workflown on any event in Nordcraft. This can be a standard JavaScript event on an element, a custom [event on a component](/components/interface-and-lifecycle#setting-up-events) or lifecycle events like `On load` or `On attribute change`.
12+
You can create a workflown on any event in Nordcraft. This can be a standard JavaScript event on an element, a custom [event on a component](/components/interface-and-lifecycle#adding-events) or lifecycle events like `On load` or `On attribute change`.
1313

1414
![The events panel is visible on the right of the editor. An onClick event has been created, and its dialog window is open. The onClick event sets the wasClicked variable to true, and then runs a workflow named increaseCounter. The workflow is identified by an icon representing three square orange nodes connected together with branches.|16/9](create-workflow-on-event.webp 'Create a workflow'){https://editor.nordcraft.com/projects/docs_examples/branches/main/components/screenshot-workflows?canvas-height=800&canvas-width=800&selection=nodes.root.events.onClick&rightpanel=events}
1515

0 commit comments

Comments
 (0)