Want to try fastn for your company's website?
Book a Demo

Visibility

Access modifiers are special keywords which can be used to control the visibility and accessibility of component arguments.

Types of Access Modifiers

fastn provides two types of access modifiers which can be used with component arguments. If not specified, then the default visibility is public for all arguments defined under component definition.
  • public (Default): This ensures that the arguments can be accessed from anywhere.
  • private: This ensures that the argument can only be accessed from within the component.

How to use them ?

To use any access modifier, you simply need to specify it while defining component argument during component definition.
Using access modifier
-- component foo:
caption name:
private boolean mouse-hovered: false

-- ftd.text: $foo.name
color: red
color if { foo.mouse-hovered }: green
$on-mouse-enter$: $ftd.set-bool($a = $foo.mouse-hovered, v = true)
$on-mouse-leave$: $ftd.set-bool($a = $foo.mouse-hovered, v = false)

-- end: foo
Lang:
ftd

Here, we have defined a simple component foo. This component is using ftd.text, a kernel component, as a definition which displays the caption name.

It has a private boolean argument mouse-hovered which can be only accessed from within the component itself. So while component invocation, we can't access this mouse-hovered argument.
Invalid component invocation
;; This should not be done
-- foo: xyz
$mouse-hovered: false
Lang:
ftd