vleam/vue
Types
An incomplete component representation piped during component definition.
See define_component
for a full example.
pub type ComponentBase(required_props, nullable_props, emits)
DebuggerEvent returned from Vue
pub type DebuggerEvent
pub type NoImmediate
pub type NoOnTrigger
NullableProp record to be used on component definition.
See define_component
for a full example.
pub type NullableProp(value) {
NullableProp(name: String)
}
Constructors
-
NullableProp(name: String)
Prop record to be used on component definition.
See define_component
for a full example.
pub type Prop(value) {
Prop(name: String, default: Option(value))
}
Constructors
-
Prop(name: String, default: Option(value))
A vue
shallowRef
pub type ShallowRef(value)
pub opaque type WatchConfig(
values,
has_immediate,
has_deep,
has_flush,
has_on_track,
has_on_trigger,
has_once,
)
pub type WatchFlush {
FlushPost
FlushSync
}
Constructors
-
FlushPost
-
FlushSync
pub type WithImmediate
pub type WithOnTrack
pub type WithOnTrigger
Functions
pub fn and_computed(
watch_config: WatchConfig(
a,
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
computed: Computed(b),
) -> WatchConfig(
a,
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
)
Add a computed
value to a watch
vue.watch_ref(first_name)
|> vue.and_computed(last_name)
|> vue.with_immediate(True)
|> vue.with_listener(fn(_, _, _) {
// ...
})
pub fn and_function(
watch_config: WatchConfig(
a,
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
function: fn() -> b,
) -> WatchConfig(
a,
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
)
Add a function to a watch
vue.watch_ref(first_name)
|> vue.and_function(last_name)
|> vue.with_immediate(True)
|> vue.with_listener(fn(_, _, _) {
// ...
})
pub fn and_plain(
watch_config: WatchConfig(
a,
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
plain: b,
) -> WatchConfig(
a,
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
)
Add a plain value to a watch
vue.watch_ref(first_name)
|> vue.and_plain(last_name)
|> vue.with_immediate(True)
|> vue.with_listener(fn(_, _, _) {
// ...
})
pub fn and_ref(
watch_config: WatchConfig(
a,
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
ref: Ref(b),
) -> WatchConfig(
a,
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
)
Add a ref
value to a watch
vue.watch_ref(first_name)
|> vue.and_ref(last_name)
|> vue.with_immediate(True)
|> vue.with_listener(fn(_, _, _) {
// ...
})
pub fn and_shallow_ref(
watch_config: WatchConfig(
a,
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
shallow_ref: ShallowRef(b),
) -> WatchConfig(
a,
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
)
Add a shallow_ref
value to a watch
vue.watch_ref(first_name)
|> vue.and_shallow_ref(last_name)
|> vue.with_immediate(True)
|> vue.with_listener(fn(_, _, _) {
// ...
})
pub fn define_component(
components components: List(#(String, fn() -> Component)),
directives directives: List(#(String, fn() -> Directive)),
inherit_attrs inherit_attrs: Bool,
) -> ComponentBase(Nil, Nil, Nil)
Entrypoint for component definition. optionally piped to a
with_n_props
and/or with_n_nullable_props
and/or with_emits
functions, and must be finally piped to setup
.
components
is a list of #(component_name, fn() -> Component) tuples. There
are three possible ways to gain access to components:
- Using
@external
to refer to a component defined in Javascript - Importing a component defined in Gleam using this library
- Using them without the need to refer them in
define_component
, either by gloabl definition withvue.component
or by an auto-import mechanism similar to Nuxt’s
directives
is a list of #(directive_name, fn() -> Directive) tuples.
inherit_attrs
is a boolean, identical to Vue’s javascript configuration.
Example
import gleam/option.{None, Some}
import gleam/string
import vleam/vue.{
type Component, NullableProp, Prop, define_component, setup,
with_1_nullable_prop, with_1_prop,
}
import vleam_todo/models.{type Todo, type TodoError}
type InputEvent
// Import the default export from HelloWorld.vue
// This is technically an incorrect type, but it'll work. C'est la vie.
@external(javascript, "/src/components/HelloWorld.vue", "default")
fn hello_world_component() -> Component
// Also works for external packages, although @ sign has to be aliased
@external(javascript, "heroicons/vue/24/solid", "UserIcon")
fn user_icon() -> Component
// or you can predefine in TS/JS
@external(javascript, "/src/ffi.ts", "CheckIcon")
fn check_icon() -> #(String, fn() -> Component)
pub fn default_export() -> Component {
define_component(
[
#("HelloWorld", hello_world_component),
#("UserIcon", user_icon),
check_icon(),
],
[],
False,
)
|> with_1_prop(
Prop("initialName", None),
)
|> with_1_nullable_prop(
Prop("greeting", Some("Hello, ")),
)
// Props are handed as Computed for reactivity. It's best practice to
// always type them, as types aren't always inferred.
|> setup(fn(
required_props: #(Computed(String)),
nullable_props: #(Computed(String)),
_
) {
let initial_name = props.0
let greeting = props.1
// Errors return from `setup` are thrown. This is just a demo, don't
// throw on bad input, only on irrecoverable errors (which generally
// should never occur in `setup` function)
use <- bool.guard(
{
greeting
|> vue.computed_value
|> string.length
}
> 0,
Error("Empty greeting"),
)
let change_count = vue.shallow_ref(0)
let increment_count = fn() {
change_count
|> vue.shallow_ref_set(vue.shallow_ref_value(change_count) + 1)
}
let name =
initial_name
|> vue.computed_value
|> vue.shallow_ref
let change_name = fn(new_name) {
name
|> vue.shallow_ref_set(new_name)
}
let full_greeting =
vue.computed(fn() {
name
|> vue.shallow_ref_value
|> string.append(
greeting
|> vue.computed_value
)
increment_count()
})
// To return values to the template, the FFI expects an Ok() with a
// tuple of object entries. The following is identical to Vue's:
//
// return {
// fullGreeting: full_greeting,
// changeName: change_name,
// changeCount: change_count,
// };
Ok(#(
#("fullGreeting", full_greeting),
#("changeName", change_name),
#("changeCount", change_count),
))
})
}
pub fn get_component(
vue_app: App,
component_name: String,
) -> Result(Component, VueError)
Returns components that were registered using app.component
pub fn inject_with_default(key: String, default: a) -> a
pub fn inject_with_factory(key: String, factory: fn() -> a) -> a
pub fn next_tick() -> Promise(Nil)
vue.nextTick() https://vuejs.org/api/general.html#nexttick
pub fn next_tick_action(callback: fn() -> Nil) -> Promise(Nil)
pub fn on_activated(handler: fn() -> Nil) -> Nil
pub fn on_before_mount(handler: fn() -> Nil) -> Nil
pub fn on_before_unmount(handler: fn() -> Nil) -> Nil
pub fn on_before_update(handler: fn() -> Nil) -> Nil
pub fn on_deactivated(handler: fn() -> Nil) -> Nil
pub fn on_mounted(handler: fn() -> Nil) -> Nil
pub fn on_track(
watch_config: WatchConfig(a, b, c, d, NoOnTrack, e, f),
on_track: Option(fn(DebuggerEvent) -> Nil),
) -> WatchConfig(a, b, c, d, WithOnTrack, e, f)
Set the on_track
callback on a watch
vue.watch_ref(first_name)
|> vue.and_computed(last_name)
|> vue.on_track(fn(_) {
// ...
})
|> vue.with_listener(fn(_, _, _) {
// ...
})
pub fn on_trigger(
watch_config: WatchConfig(a, b, c, d, e, NoOnTrigger, f),
on_trigger: Option(fn(DebuggerEvent) -> Nil),
) -> WatchConfig(a, b, c, d, e, WithOnTrigger, f)
Set the on_trigger
callback on a watch
vue.watch_ref(first_name)
|> vue.and_computed(last_name)
|> vue.on_trigger(fn(_) {
// ...
})
|> vue.with_listener(fn(_, _, _) {
// ...
})
pub fn on_unmounted(handler: fn() -> Nil) -> Nil
pub fn on_updated(handler: fn() -> Nil) -> Nil
pub fn register_component(
vue_app: App,
component_name: String,
component: Component,
) -> App
Registers components using app.component
pub fn setup(
base: ComponentBase(a, b, c),
setup: fn(a, b, c) -> d,
) -> Component
Component setup function
See define_component
for a full example.
pub fn shallow_ref_set(
ref: ShallowRef(a),
value: a,
) -> ShallowRef(a)
Set shallow ref value
pub fn watch2(
watches watches: #(
WatchConfig(
#(a),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(b),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
),
) -> WatchConfig(
#(a, b),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
)
Define a watcher for 2 “reflike” values. You can use and_
modifiers to add
values to the watch, with_
modifiers to set options, and with_listener
for the listen function.
vue.watch2(#(
watch_computed(last_name),
watch_ref(last_name),
))
|> vue.with_immediate(True)
|> vue.with_listener(fn(values, old_values, _) {
// this will fire on a change in `first_name` or `last_name`
// values, old_values, is a tuple corresponding to the input
})
If you don’t need the new
and old
values or only watch a single value,
use the quantity-agnostic watch_
and and_
functions by themselves.
pub fn watch3(
watches watches: #(
WatchConfig(
#(a),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(b),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(c),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
),
) -> WatchConfig(
#(a, b, c),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
)
Define a watcher for 3 “reflike” values. You can use and_
modifiers to add
values to the watch, with_
modifiers to set options, and with_listener
for the listen function.
vue.watch3(#(
watch_computed(last_name),
watch_ref(last_name),
watch_shallow_ref(that_uncle_name),
))
|> vue.with_immediate(True)
|> vue.with_listener(fn(values, old_values, _) {
// this will fire on a change in `first_name` or `last_name`
// values, old_values, is a tuple corresponding to the input
})
If you don’t need the new
and old
values or only watch a single value,
use the quantity-agnostic watch_
and and_
functions by themselves.
pub fn watch4(
watches watches: #(
WatchConfig(
#(a),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(b),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(c),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(d),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
),
) -> WatchConfig(
#(a, b, c, d),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
)
Define a watcher for 4 “reflike” values. You can use and_
modifiers to add
values to the watch, with_
modifiers to set options, and with_listener
for the listen function.
vue.watch4(#(
watch_computed(last_name),
watch_ref(last_name),
watch_shallow_ref(that_annoying_guy),
watch_shallow_ref(his_annoying_brother),
))
|> vue.with_immediate(True)
|> vue.with_listener(fn(values, old_values, _) {
// this will fire on a change in `first_name` or `last_name`
// values, old_values, is a tuple corresponding to the input
})
If you don’t need the new
and old
values or only watch a single value,
use the quantity-agnostic watch_
and and_
functions by themselves.
pub fn watch5(
watches watches: #(
WatchConfig(
#(a),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(b),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(c),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(d),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(e),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
),
) -> WatchConfig(
#(a, b, c, d, e),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
)
Define a watcher for 5 “reflike” values. You can use and_
modifiers to add
values to the watch, with_
modifiers to set options, and with_listener
for the listen function.
vue.watch5(#(
watch_computed(last_name),
watch_ref(last_name),
watch_shallow_ref(that_annoying_guy),
watch_shallow_ref(his_annoying_brother),
watch_computed(grades),
))
|> vue.with_immediate(True)
|> vue.with_listener(fn(values, old_values, _) {
// this will fire on a change in `first_name` or `last_name`
// values, old_values, is a tuple corresponding to the input
})
If you don’t need the new
and old
values or only watch a single value,
use the quantity-agnostic watch_
and and_
functions by themselves.
pub fn watch6(
watches watches: #(
WatchConfig(
#(a),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(b),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(c),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(d),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(e),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(f),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
),
) -> WatchConfig(
#(a, b, c, d, e, f),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
)
Define a watcher for 6 “reflike” values. You can use and_
modifiers to add
values to the watch, with_
modifiers to set options, and with_listener
for the listen function.
vue.watch6(#(
watch_computed(last_name),
watch_ref(last_name),
watch_shallow_ref(that_annoying_guy),
watch_shallow_ref(his_annoying_brother),
watch_computed(grades),
watch_computed(passes),
))
|> vue.with_immediate(True)
|> vue.with_listener(fn(values, old_values, _) {
// this will fire on a change in `first_name` or `last_name`
// values, old_values, is a tuple corresponding to the input
})
If you don’t need the new
and old
values or only watch a single value,
use the quantity-agnostic watch_
and and_
functions by themselves.
pub fn watch7(
watches watches: #(
WatchConfig(
#(a),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(b),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(c),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(d),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(e),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(f),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(g),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
),
) -> WatchConfig(
#(a, b, c, d, e, f, g),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
)
Define a watcher for 7 “reflike” values. You can use and_
modifiers to add
values to the watch, with_
modifiers to set options, and with_listener
for the listen function.
vue.watch7(#(
watch_computed(last_name),
watch_ref(last_name),
watch_shallow_ref(that_annoying_guy),
watch_shallow_ref(his_annoying_brother),
watch_computed(grades),
watch_computed(passes),
watch_computed(fails),
))
|> vue.with_immediate(True)
|> vue.with_listener(fn(values, old_values, _) {
// this will fire on a change in `first_name` or `last_name`
// values, old_values, is a tuple corresponding to the input
})
If you don’t need the new
and old
values or only watch a single value,
use the quantity-agnostic watch_
and and_
functions by themselves.
pub fn watch8(
watches watches: #(
WatchConfig(
#(a),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(b),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(c),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(d),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(e),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(f),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(g),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(h),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
),
) -> WatchConfig(
#(a, b, c, d, e, f, g, h),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
)
Define a watcher for 8 “reflike” values. You can use and_
modifiers to add
values to the watch, with_
modifiers to set options, and with_listener
for the listen function.
vue.watch8(#(
watch_computed(last_name),
watch_ref(last_name),
watch_shallow_ref(that_annoying_guy),
watch_shallow_ref(his_annoying_brother),
watch_computed(grades),
watch_computed(passes),
watch_computed(fails),
watch_computed(average_grade),
))
|> vue.with_immediate(True)
|> vue.with_listener(fn(values, old_values, _) {
// this will fire on a change in `first_name` or `last_name`
// values, old_values, is a tuple corresponding to the input
})
If you don’t need the new
and old
values or only watch a single value,
use the quantity-agnostic watch_
and and_
functions by themselves.
pub fn watch9(
watches watches: #(
WatchConfig(
#(a),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(b),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(c),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(d),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(e),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(f),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(g),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(h),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
WatchConfig(
#(i),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
),
) -> WatchConfig(
#(a, b, c, d, e, f, g, h, i),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
)
Define a watcher for 9 “reflike” values. You can use and_
modifiers to add
values to the watch, with_
modifiers to set options, and with_listener
for the listen function.
vue.watch9(#(
watch_computed(last_name),
watch_ref(last_name),
watch_shallow_ref(that_annoying_guy),
watch_shallow_ref(his_annoying_brother),
watch_computed(grades),
watch_computed(passes),
watch_computed(fails),
watch_computed(average_grade),
watch_computed(standard_deviation),
))
|> vue.with_immediate(True)
|> vue.with_listener(fn(values, old_values, _) {
// this will fire on a change in `first_name` or `last_name`
// values, old_values, is a tuple corresponding to the input
})
If you don’t need the new
and old
values or only watch a single value,
use the quantity-agnostic watch_
and and_
functions by themselves.
pub fn watch_computed(
computed: Computed(a),
) -> WatchConfig(
#(b),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
)
Define a watcher for a vue computed
. You can use and_
modifiers to add
values to the watch, with_
modifiers to set options, and with_listener
for the listen function.
vue.watch_computed(first_name)
|> vue.and_ref(last_name)
|> vue.with_immediate(True)
|> vue.with_listener(fn(_, _, _) {
// this will fire on a change in `first_name` or `last_name`
// old, new values are unavailable
})
If you need the new
and old
values when more than a single value is
watched, use the quantity-aware watchX
functions.
pub fn watch_function(
function: fn() -> a,
) -> WatchConfig(
#(b),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
)
Define a watcher for a function. You can use and_
modifiers to add
values to the watch, with_
modifiers to set options, and with_listener
for the listen function.
vue.watch_function(get_first_name)
|> vue.and_computed(last_name)
|> vue.with_immediate(True)
|> vue.with_listener(fn(_, _, _) {
// this will fire on a change in `first_name` or `last_name`
// old, new values are unavailable
})
If you need the new
and old
values when more than a single value is
watched, use the quantity-aware watchX
functions.
pub fn watch_plain(
plain: a,
) -> WatchConfig(
#(b),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
)
Define a watcher for a plain value. You can use and_
modifiers to add
values to the watch, with_
modifiers to set options, and with_listener
for the listen function.
vue.watch_plain(first_name)
|> vue.and_shallow_ref(last_name)
|> vue.with_immediate(True)
|> vue.with_listener(fn(_, _, _) {
// this will fire on a change in `first_name` or `last_name`
// old, new values are unavailable
})
If you need the new
and old
values when more than a single value is
watched, use the quantity-aware watchX
functions.
pub fn watch_ref(
ref: Ref(a),
) -> WatchConfig(
#(b),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
)
Define a watcher for a vue ref
. You can use and_
modifiers to add
values to the watch, with_
modifiers to set options, and with_listener
for the listen function.
vue.watch_ref(first_name)
|> vue.and_computed(last_name)
|> vue.with_immediate(True)
|> vue.with_listener(fn(_, _, _) {
// this will fire on a change in `first_name` or `last_name`
// old, new values are unavailable
})
If you need the new
and old
values when more than a single value is
watched, use the quantity-aware watchX
functions.
pub fn watch_shallow_ref(
shallow_ref: ShallowRef(a),
) -> WatchConfig(
#(b),
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
)
Define a watcher for a vue shallow_ref
. You can use and_
modifiers to add
values to the watch, with_
modifiers to set options, and with_listener
for the listen function.
vue.watch_shallow_ref(first_name)
|> vue.and_computed(last_name)
|> vue.with_immediate(True)
|> vue.with_listener(fn(_, _, _) {
// this will fire on a change in `first_name` or `last_name`
// old, new values are unavailable
})
If you need the new
and old
values when more than a single value is
watched, use the quantity-aware watchX
functions.
pub fn with_1_nullable_prop(
component: ComponentBase(a, b, c),
prop_1: NullableProp(d),
) -> ComponentBase(a, #(Computed(Option(d))), c)
Define 1 nullable prop on a component
See define_component
for a full example.
pub fn with_1_prop(
component: ComponentBase(a, b, c),
prop_1: Prop(d),
) -> ComponentBase(#(Computed(d)), b, c)
Define 1 prop on a component
See define_component
for a full example.
pub fn with_2_nullable_props(
component: ComponentBase(a, b, c),
prop_1: NullableProp(d),
prop_2: NullableProp(e),
) -> ComponentBase(
a,
#(Computed(Option(d)), Computed(Option(e))),
c,
)
Define 2 nullable props on a component
See define_component
for a full example.
pub fn with_2_props(
component: ComponentBase(a, b, c),
prop_1: Prop(d),
prop_2: Prop(e),
) -> ComponentBase(#(Computed(d), Computed(e)), b, c)
Define 2 props on a component
See define_component
for a full example.
pub fn with_3_nullable_props(
component: ComponentBase(a, b, c),
prop_1: NullableProp(d),
prop_2: NullableProp(e),
prop_3: NullableProp(f),
) -> ComponentBase(
a,
#(Computed(Option(d)), Computed(Option(e)), Computed(Option(f))),
c,
)
Define 3 nullable props on a component
See define_component
for a full example.
pub fn with_3_props(
component: ComponentBase(a, b, c),
prop_1: Prop(d),
prop_2: Prop(e),
prop_3: Prop(f),
) -> ComponentBase(#(Computed(d), Computed(e), Computed(f)), b, c)
Define 3 props on a component
See define_component
for a full example.
pub fn with_4_nullable_props(
component: ComponentBase(a, b, c),
prop_1: NullableProp(d),
prop_2: NullableProp(e),
prop_3: NullableProp(f),
prop_4: NullableProp(g),
) -> ComponentBase(
a,
#(
Computed(Option(d)),
Computed(Option(e)),
Computed(Option(f)),
Computed(Option(g)),
),
c,
)
Define 4 nullable props on a component
See define_component
for a full example.
pub fn with_4_props(
component: ComponentBase(a, b, c),
prop_1: Prop(d),
prop_2: Prop(e),
prop_3: Prop(f),
prop_4: Prop(g),
) -> ComponentBase(
#(Computed(d), Computed(e), Computed(f), Computed(g)),
b,
c,
)
Define 4 props on a component
See define_component
for a full example.
pub fn with_5_nullable_props(
component: ComponentBase(a, b, c),
prop_1: NullableProp(d),
prop_2: NullableProp(e),
prop_3: NullableProp(f),
prop_4: NullableProp(g),
prop_5: NullableProp(h),
) -> ComponentBase(
a,
#(
Computed(Option(d)),
Computed(Option(e)),
Computed(Option(f)),
Computed(Option(g)),
Computed(Option(h)),
),
c,
)
Define 5 nullable props on a component
See define_component
for a full example.
pub fn with_5_props(
component: ComponentBase(a, b, c),
prop_1: Prop(d),
prop_2: Prop(e),
prop_3: Prop(f),
prop_4: Prop(g),
prop_5: Prop(h),
) -> ComponentBase(
#(
Computed(d),
Computed(e),
Computed(f),
Computed(g),
Computed(h),
),
b,
c,
)
Define 5 props on a component
See define_component
for a full example.
pub fn with_6_nullable_props(
component: ComponentBase(a, b, c),
prop_1: NullableProp(d),
prop_2: NullableProp(e),
prop_3: NullableProp(f),
prop_4: NullableProp(g),
prop_5: NullableProp(h),
prop_6: NullableProp(i),
) -> ComponentBase(
a,
#(
Computed(Option(d)),
Computed(Option(e)),
Computed(Option(f)),
Computed(Option(g)),
Computed(Option(h)),
Computed(Option(i)),
),
c,
)
Define 6 nullable props on a component
See define_component
for a full example.
pub fn with_6_props(
component: ComponentBase(a, b, c),
prop_1: Prop(d),
prop_2: Prop(e),
prop_3: Prop(f),
prop_4: Prop(g),
prop_5: Prop(h),
prop_6: Prop(i),
) -> ComponentBase(
#(
Computed(d),
Computed(e),
Computed(f),
Computed(g),
Computed(h),
Computed(i),
),
b,
c,
)
Define 6 props on a component
See define_component
for a full example.
pub fn with_7_nullable_props(
component: ComponentBase(a, b, c),
prop_1: NullableProp(d),
prop_2: NullableProp(e),
prop_3: NullableProp(f),
prop_4: NullableProp(g),
prop_5: NullableProp(h),
prop_6: NullableProp(i),
prop_7: NullableProp(j),
) -> ComponentBase(
a,
#(
Computed(Option(d)),
Computed(Option(e)),
Computed(Option(f)),
Computed(Option(g)),
Computed(Option(h)),
Computed(Option(i)),
Computed(Option(j)),
),
c,
)
Define 7 nullable props on a component
See define_component
for a full example.
pub fn with_7_props(
component: ComponentBase(a, b, c),
prop_1: Prop(d),
prop_2: Prop(e),
prop_3: Prop(f),
prop_4: Prop(g),
prop_5: Prop(h),
prop_6: Prop(i),
prop_7: Prop(j),
) -> ComponentBase(
#(
Computed(d),
Computed(e),
Computed(f),
Computed(g),
Computed(h),
Computed(i),
Computed(j),
),
b,
c,
)
Define 7 props on a component
See define_component
for a full example.
pub fn with_8_nullable_props(
component: ComponentBase(a, b, c),
prop_1: NullableProp(d),
prop_2: NullableProp(e),
prop_3: NullableProp(f),
prop_4: NullableProp(g),
prop_5: NullableProp(h),
prop_6: NullableProp(i),
prop_7: NullableProp(j),
prop_8: NullableProp(k),
) -> ComponentBase(
a,
#(
Computed(Option(d)),
Computed(Option(e)),
Computed(Option(f)),
Computed(Option(g)),
Computed(Option(h)),
Computed(Option(i)),
Computed(Option(j)),
Computed(Option(k)),
),
c,
)
Define 8 nullable props on a component
See define_component
for a full example.
pub fn with_8_props(
component: ComponentBase(a, b, c),
prop_1: Prop(d),
prop_2: Prop(e),
prop_3: Prop(f),
prop_4: Prop(g),
prop_5: Prop(h),
prop_6: Prop(i),
prop_7: Prop(j),
prop_8: Prop(k),
) -> ComponentBase(
#(
Computed(d),
Computed(e),
Computed(f),
Computed(g),
Computed(h),
Computed(i),
Computed(j),
Computed(k),
),
b,
c,
)
Define 8 props on a component
See define_component
for a full example.
pub fn with_9_nullable_props(
component: ComponentBase(a, b, c),
prop_1: NullableProp(d),
prop_2: NullableProp(e),
prop_3: NullableProp(f),
prop_4: NullableProp(g),
prop_5: NullableProp(h),
prop_6: NullableProp(i),
prop_7: NullableProp(j),
prop_8: NullableProp(k),
prop_9: NullableProp(l),
) -> ComponentBase(
a,
#(
Computed(Option(d)),
Computed(Option(e)),
Computed(Option(f)),
Computed(Option(g)),
Computed(Option(h)),
Computed(Option(i)),
Computed(Option(j)),
Computed(Option(k)),
Computed(Option(l)),
),
c,
)
Define 9 nullable props on a component
See define_component
for a full example.
pub fn with_9_props(
component: ComponentBase(a, b, c),
prop_1: Prop(d),
prop_2: Prop(e),
prop_3: Prop(f),
prop_4: Prop(g),
prop_5: Prop(h),
prop_6: Prop(i),
prop_7: Prop(j),
prop_8: Prop(k),
prop_9: Prop(l),
) -> ComponentBase(
#(
Computed(d),
Computed(e),
Computed(f),
Computed(g),
Computed(h),
Computed(i),
Computed(j),
Computed(k),
Computed(l),
),
b,
c,
)
Define 9 props on a component
See define_component
for a full example.
pub fn with_deep(
watch_config: WatchConfig(a, b, NoDeep, c, d, e, f),
deep: Bool,
) -> WatchConfig(a, b, WithDeep, c, d, e, f)
Set the deep
option on a watch
vue.watch_ref(first_name)
|> vue.and_computed(last_name)
|> vue.with_deep(True)
|> vue.with_listener(fn(_, _, _) {
// ...
})
pub fn with_emits(
base: ComponentBase(a, b, c),
emits: List(String),
) -> ComponentBase(a, d, e)
Define emits on a component
pub fn with_flush(
watch_config: WatchConfig(a, b, c, NoFlush, d, e, f),
flush: WatchFlush,
) -> WatchConfig(a, b, c, WithFlush, d, e, f)
Set the flush
option on a watch
vue.watch_ref(first_name)
|> vue.and_computed(last_name)
|> vue.with_flush(vue.FlushPost)
|> vue.with_listener(fn(_, _, _) {
// ...
})
pub fn with_immediate(
watch_config: WatchConfig(a, NoImmediate, b, c, d, e, f),
immediate: Bool,
) -> WatchConfig(a, WithImmediate, b, c, d, e, f)
Set the immediate
option on a watch
vue.watch_ref(first_name)
|> vue.and_computed(last_name)
|> vue.with_immediate(True)
|> vue.with_listener(fn(_, _, _) {
// ...
})
pub fn with_listener(
watch_config: WatchConfig(a, b, c, d, e, f, g),
callback: fn(a, a, fn(fn() -> Nil) -> Nil) -> Nil,
) -> Nil
Set the listener for a watch
vue.watch_ref(first_name)
|> vue.and_computed(last_name)
|> vue.with_listener(fn(_, _, _) {
// ...
})
If you need the new
and old
values when more than a single value is
watched, use the quantity-aware watchX
functions along with this.