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
Copy file name to clipboardExpand all lines: component-model/src/tutorial.md
+14-21Lines changed: 14 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,11 +16,7 @@ Wasm components, we will compose them into a single runnable component, and test
16
16
## The calculator interface
17
17
18
18
For tutorial purposes, we are going to put our "calculator engine" and "addition operation" interfaces into two separate WIT packages, each containing one WIT file. This may seem excessive, but the reason is to illustrate real-world use cases where components come from different authors and packages.
19
-
These files can be found in the component book repository in the [`wit` directory](https://github.com/bytecodealliance/component-docs/tree/main/component-model/examples/tutorial/wit) under `wit/adder/world.wit` and `wit/calculator/world.wit`. These files define:
20
-
21
-
* A world describing an world that exports the "add" interface. Again, components such as the calculator can call it when
22
-
they need to add numbers.
23
-
19
+
These files can be found in the component book repository in the [`wit` directory](https://github.com/bytecodealliance/component-docs/tree/main/component-model/examples/tutorial/wit) under `wit/adder/world.wit` and `wit/calculator/world.wit`:
24
20
```wit
25
21
// wit/adder/world.wit
26
22
package docs:adder@0.1.0;
@@ -32,23 +28,7 @@ These files can be found in the component book repository in the [`wit` director
32
28
world adder {
33
29
export add;
34
30
}
35
-
```
36
-
37
-
* An interface for the calculator itself. We'll use this later to carry out calculations. It
38
-
contains an evaluate function, and an enum that delineates the operations that can be involved in
39
-
a calculation. In this tutorial, the only operation is `add`.
40
-
* Interfaces for the various operations the calculator might need to carry out as part of a
41
-
calculation. For the tutorial, again, the only import we define is for the "add" operation from
42
-
the "docs:adder" world defined previously.
43
-
* A world describing the calculator component. This world exports the calculator interface, meaning
44
-
that other components can call it to perform calculations. It imports the operation interfaces
45
-
(such as "add"), meaning it relies on other components to perform those operations.
46
-
* A world describing the "primary" app component, which imports the "calculate" interface. This is
47
-
the component will take in command line arguments and pass them to the "eval-expression" function
48
-
of the calculator component.
49
31
50
-
51
-
```wit
52
32
// wit/calculator/world.wit
53
33
package docs:calculator@0.1.0;
54
34
@@ -70,6 +50,19 @@ These files can be found in the component book repository in the [`wit` director
70
50
71
51
```
72
52
53
+
These files define:
54
+
* A world `adder` that exports the `add` interface. Again, components such as the calculator can call it when
55
+
they need to add numbers.
56
+
* A world `calculator` describing the calculator component. This world exports the calculator interface, meaning
57
+
that other components can call it to perform calculations. It imports the operation interfaces
58
+
(such as `add`), meaning it relies on other components to perform those operations.
59
+
* An interface `calculate` that contains an evaluate function and an enum that delineates
60
+
the operations that can be involved in a calculation. In this tutorial, the only operation is `add`.
61
+
* A world `app` describing the "primary" app component, which imports the `calculate` interface.
62
+
This component will take in command line arguments and pass them to the `eval-expression` function
63
+
of the calculator component.
64
+
65
+
73
66
## Create an `add` component
74
67
75
68
Reference the [language guide](language-support.md) and [authoring components
0 commit comments