You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 6850488
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/components/compositions/index.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,7 +53,7 @@ Benefits of nesting include:
53
53
When nesting components, consider the following:
54
54
55
55
-**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)
57
57
-**Styling**: Parent components can [style the root element](/styling/conditional-styles#component-style-overrides) of nested components
Copy file name to clipboardExpand all lines: docs/components/interface-and-lifecycle/index.md
+17-12Lines changed: 17 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,18 @@
1
1
---
2
2
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.
4
4
---
5
5
6
6
# Interface and lifecycle
7
7
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.
9
9
10
10
## Component interface
11
11
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:
13
13
14
14
-[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)
16
16
-[Contexts](#data-flow-with-contexts): Data flow between parent and any descendant components
17
17
18
18
::: tip
@@ -48,14 +48,14 @@ For example, a **tooltip** component might use attributes to control:
48
48
- Whether the tooltip has a close button
49
49
50
50
::: 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.
52
52
:::
53
53
54
54
::: 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.
56
56
:::
57
57
58
-
### Setting up events
58
+
### Adding events
59
59
60
60
{https://editor.nordcraft.com/projects/docs_examples/branches/main/components/screenshot-card-container?canvas-width=800&rightpanel=style&selection=events.0&canvas-height=800}
61
61
@@ -69,7 +69,7 @@ Events allow components to communicate upward to parent elements:
69
69
Events enable child components to send messages and data up to their parent components.
70
70
71
71
::: 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.
73
73
:::
74
74
75
75
### Triggering events
@@ -87,12 +87,17 @@ Unlike HTML element events that trigger automatically on user interactions, comp
87
87
88
88
1. Click the `+` button to add a new action
89
89
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
91
91
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.
94
94
:::
95
95
96
+
@@@ youtube
97
+
videoId: gttYD_Aftc8
98
+
title: Using component events
99
+
@@@
100
+
96
101
## Data flow with contexts
97
102
98
103
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
162
167
- Reset when the component is removed and added again
163
168
164
169
::: 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.
Copy file name to clipboardExpand all lines: docs/contexts/overview/index.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ Contexts in Nordcraft provide a way to share data and functionality between comp
10
10
In traditional component architecture, data typically flows in two ways:
11
11
12
12
-**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)
14
14
15
15
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.
Copy file name to clipboardExpand all lines: docs/workflows/working-with-workflows/index.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ Learn how to create event-triggered and reusable workflows with parameters and s
9
9
10
10
## Create a workflow
11
11
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`.
13
13
14
14
{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}
0 commit comments