WEBVTT

00:00:00.500 --> 00:00:02.049
The Shop needs a tax rate.

00:00:02.950 --> 00:00:05.228
An admin sets it and checkout will read it.

00:00:06.127 --> 00:00:09.590
That is one saved number, and it gets a module of its own called

00:00:09.603 --> 00:00:10.293
Settings.

00:00:11.192 --> 00:00:13.431
The first file is memory, v one.

00:00:14.330 --> 00:00:17.819
Data lists what the module saves, here a single tax field that

00:00:17.832 --> 00:00:19.551
only Settings code can see.

00:00:20.450 --> 00:00:22.494
The memory attribute names the owner.

00:00:23.392 --> 00:00:26.739
Other modules will refer to Memory, and never to the fields.

00:00:27.637 --> 00:00:31.009
Beside it, the selector says which version the service uses

00:00:31.022 --> 00:00:31.543
today.

00:00:32.442 --> 00:00:34.421
The module also gets a constructor.

00:00:35.319 --> 00:00:38.731
It creates fresh Settings data with a tax of zero and returns

00:00:38.744 --> 00:00:40.775
it as a ticket for the parent to attach.

00:00:42.933 --> 00:00:45.393
The service is declared in mod dot r s.

00:00:46.294 --> 00:00:49.458
The service attribute connects it to the current memory version.

00:00:50.356 --> 00:00:51.711
Tax is a read method.

00:00:52.609 --> 00:00:54.445
Set tax needs a write scope.

00:00:55.343 --> 00:00:58.872
It refuses a rate above ten thousand before it touches the data,

00:00:59.120 --> 00:01:00.330
and only then writes.

00:01:02.467 --> 00:01:04.302
The root has a memory file too.

00:01:05.203 --> 00:01:07.117
It saves no fields of its own.

00:01:08.015 --> 00:01:11.101
It lists the modules attached to it, one slot each.

00:01:12.000 --> 00:01:15.633
The settings slot names Settings memory, version one, exactly.

00:01:16.531 --> 00:01:20.086
Install runs once, when the canister is first installed.

00:01:20.984 --> 00:01:24.851
It creates the root, calls each module's constructor, and attaches

00:01:24.864 --> 00:01:26.114
the result to its slot.

00:01:27.013 --> 00:01:29.448
Creating and attaching happen in the same scope.

00:01:30.346 --> 00:01:33.354
A ticket that is never attached is discarded when the scope

00:01:33.367 --> 00:01:33.836
ends.

00:01:34.734 --> 00:01:36.453
Data alone is not callable.

00:01:37.351 --> 00:01:40.307
Bind looks up the settings slot and builds the Settings service

00:01:40.320 --> 00:01:40.737
from it.

00:01:41.635 --> 00:01:44.734
The App keeps that service in a field marked service, which

00:01:44.747 --> 00:01:47.104
gives endpoints the call app dot settings.

00:01:48.002 --> 00:01:50.945
The root attribute names two startup callbacks.

00:01:51.844 --> 00:01:55.385
Init runs on first install and ends by binding the services.

00:01:56.284 --> 00:01:58.393
Restore runs after an upgrade.

00:01:59.292 --> 00:02:02.260
It opens the saved data and binds the services again.

00:02:03.159 --> 00:02:06.284
Services are rebuilt every time the program starts.

00:02:07.182 --> 00:02:08.667
Only the data is kept.

00:02:10.800 --> 00:02:12.635
Two endpoints finish the feature.

00:02:13.536 --> 00:02:16.609
Set tax is an update that only a controller may call.

00:02:17.507 --> 00:02:19.187
Tax is a query for anyone.

00:02:20.085 --> 00:02:23.705
Setting five hundred returns true, and the saved tax is five

00:02:23.718 --> 00:02:24.200
hundred.

00:02:25.098 --> 00:02:27.117
The Shop test checks both paths.

00:02:28.015 --> 00:02:32.312
It sets the tax, drops the app, opens it again, and reads five

00:02:32.325 --> 00:02:32.807
hundred.

00:02:33.705 --> 00:02:37.117
A second test confirms that ten thousand and one is refused

00:02:37.130 --> 00:02:38.783
and ten thousand is accepted.

