Appearance
Direction
On this page you find the documentation for the Direction class.
Introduction
The Direction class represents a transition from one Page to another Page. It consists of the following parts:
page: A value indicating whichPagethe user should come tocondition: A function indicating under which circumstance theDirectionshould be useddescription: A text describing the condition in theDirection(used for documentation only)
A Page usually contains multiple Directions, and when the user has interacted with the Page (for example clicked on a Button), the first Direction in the Page whose condition returns back true will be used to transition to the page in that Direction.
Creating a Direction
All parts a Direction consists of are specified when creating the instance of the Direction. To create a new Direction, pass the constructor the parts:
- A value indicating which
PagetheDirectionleads to, such as:MyPage(a reference to thePageclass)new MyPage()(an instance of thePageclass)() => new MyPage()(a function returning thePageinstance)
- A function (the condition) returning
truewhen theDirectionshould be used, such as:() => Math.random() < 0.5
- An optional string describing when the condition returns
true, such as:"Fifty-fifty"
Example
Example showing how to create a new Direction.
js
const myDirection = new Direction(
GoodNightPage,
() => 20 < new Date().getHours(),
"Time to sleep",
)
The direction can then be added to a Page using for example Page.createAfterDirections().