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.Option(value))
}
Constructors
-
Prop(name: String, default: option.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
Values
pub fn and_computed(
watch_config: WatchConfig(
unknown,
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
computed: Computed(value),
) -> WatchConfig(
unknown,
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(
unknown,
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
function: fn() -> value,
) -> WatchConfig(
unknown,
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(
unknown,
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
plain: value,
) -> WatchConfig(
unknown,
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(
unknown,
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
ref: Ref(value),
) -> WatchConfig(
unknown,
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(
unknown,
NoImmediate,
NoDeep,
NoFlush,
NoOnTrack,
NoOnTrigger,
NoOnce,
),
shallow_ref: ShallowRef(value),
) -> WatchConfig(
unknown,
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
@externalto 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.componentor 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", vue.required()),
)
|> with_1_nullable_prop(
Prop("greeting", vue.with_default("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(key: String) -> option.Option(value)
pub fn inject_with_default(key: String, default: value) -> value
pub fn inject_with_factory(
key: String,
factory: fn() -> value,
) -> value
pub fn next_tick() -> promise.Promise(Nil)
vue.nextTick() https://vuejs.org/api/general.html#nexttick
pub fn next_tick_action(
callback: fn() -> Nil,
) -> promise.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(
values,
has_immediate,
has_deep,
has_flush,
NoOnTrack,
has_on_trigger,
has_once,
),
on_track: option.Option(fn(DebuggerEvent) -> Nil),
) -> WatchConfig(
values,
has_immediate,
has_deep,
has_flush,
WithOnTrack,
has_on_trigger,
has_once,
)
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(
values,
has_immediate,
has_deep,
has_flush,
has_on_track,
NoOnTrigger,
has_once,
),
on_trigger: option.Option(fn(DebuggerEvent) -> Nil),
) -> WatchConfig(
values,
has_immediate,
has_deep,
has_flush,
has_on_track,
WithOnTrigger,
has_once,
)
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 required() -> option.Option(default)
Convenience function to make Prop definitions more readable
Prop("name", required())
pub fn setup(
base: ComponentBase(required_props, nullable_props, emits),
setup: fn(required_props, nullable_props, emits) -> a,
) -> Component
Component setup function
See define_component for a full example.
pub fn shallow_ref_set(
ref: ShallowRef(value),
value: value,
) -> ShallowRef(value)
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(value),
) -> WatchConfig(
#(unknown),
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() -> value,
) -> WatchConfig(
#(unknown),
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: value,
) -> WatchConfig(
#(unknown),
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(value),
) -> WatchConfig(
#(unknown),
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(value),
) -> WatchConfig(
#(unknown),
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(required_props, nullable_props, emits),
prop_1: NullableProp(p1),
) -> ComponentBase(
required_props,
#(Computed(option.Option(p1))),
emits,
)
Define 1 nullable prop on a component
See define_component for a full example.
pub fn with_1_prop(
component: ComponentBase(required_props, nullable_props, emits),
prop_1: Prop(p1),
) -> ComponentBase(#(Computed(p1)), nullable_props, emits)
Define 1 prop on a component
See define_component for a full example.
pub fn with_2_nullable_props(
component: ComponentBase(required_props, nullable_props, emits),
prop_1: NullableProp(p1),
prop_2: NullableProp(p2),
) -> ComponentBase(
required_props,
#(Computed(option.Option(p1)), Computed(option.Option(p2))),
emits,
)
Define 2 nullable props on a component
See define_component for a full example.
pub fn with_2_props(
component: ComponentBase(required_props, nullable_props, emits),
prop_1: Prop(p1),
prop_2: Prop(p2),
) -> ComponentBase(
#(Computed(p1), Computed(p2)),
nullable_props,
emits,
)
Define 2 props on a component
See define_component for a full example.
pub fn with_3_nullable_props(
component: ComponentBase(required_props, nullable_props, emits),
prop_1: NullableProp(p1),
prop_2: NullableProp(p2),
prop_3: NullableProp(p3),
) -> ComponentBase(
required_props,
#(
Computed(option.Option(p1)),
Computed(option.Option(p2)),
Computed(option.Option(p3)),
),
emits,
)
Define 3 nullable props on a component
See define_component for a full example.
pub fn with_3_props(
component: ComponentBase(required_props, nullable_props, emits),
prop_1: Prop(p1),
prop_2: Prop(p2),
prop_3: Prop(p3),
) -> ComponentBase(
#(Computed(p1), Computed(p2), Computed(p3)),
nullable_props,
emits,
)
Define 3 props on a component
See define_component for a full example.
pub fn with_4_nullable_props(
component: ComponentBase(required_props, nullable_props, emits),
prop_1: NullableProp(p1),
prop_2: NullableProp(p2),
prop_3: NullableProp(p3),
prop_4: NullableProp(p4),
) -> ComponentBase(
required_props,
#(
Computed(option.Option(p1)),
Computed(option.Option(p2)),
Computed(option.Option(p3)),
Computed(option.Option(p4)),
),
emits,
)
Define 4 nullable props on a component
See define_component for a full example.
pub fn with_4_props(
component: ComponentBase(required_props, nullable_props, emits),
prop_1: Prop(p1),
prop_2: Prop(p2),
prop_3: Prop(p3),
prop_4: Prop(p4),
) -> ComponentBase(
#(Computed(p1), Computed(p2), Computed(p3), Computed(p4)),
nullable_props,
emits,
)
Define 4 props on a component
See define_component for a full example.
pub fn with_5_nullable_props(
component: ComponentBase(required_props, nullable_props, emits),
prop_1: NullableProp(p1),
prop_2: NullableProp(p2),
prop_3: NullableProp(p3),
prop_4: NullableProp(p4),
prop_5: NullableProp(p5),
) -> ComponentBase(
required_props,
#(
Computed(option.Option(p1)),
Computed(option.Option(p2)),
Computed(option.Option(p3)),
Computed(option.Option(p4)),
Computed(option.Option(p5)),
),
emits,
)
Define 5 nullable props on a component
See define_component for a full example.
pub fn with_5_props(
component: ComponentBase(required_props, nullable_props, emits),
prop_1: Prop(p1),
prop_2: Prop(p2),
prop_3: Prop(p3),
prop_4: Prop(p4),
prop_5: Prop(p5),
) -> ComponentBase(
#(
Computed(p1),
Computed(p2),
Computed(p3),
Computed(p4),
Computed(p5),
),
nullable_props,
emits,
)
Define 5 props on a component
See define_component for a full example.
pub fn with_6_nullable_props(
component: ComponentBase(required_props, nullable_props, emits),
prop_1: NullableProp(p1),
prop_2: NullableProp(p2),
prop_3: NullableProp(p3),
prop_4: NullableProp(p4),
prop_5: NullableProp(p5),
prop_6: NullableProp(p6),
) -> ComponentBase(
required_props,
#(
Computed(option.Option(p1)),
Computed(option.Option(p2)),
Computed(option.Option(p3)),
Computed(option.Option(p4)),
Computed(option.Option(p5)),
Computed(option.Option(p6)),
),
emits,
)
Define 6 nullable props on a component
See define_component for a full example.
pub fn with_6_props(
component: ComponentBase(required_props, nullable_props, emits),
prop_1: Prop(p1),
prop_2: Prop(p2),
prop_3: Prop(p3),
prop_4: Prop(p4),
prop_5: Prop(p5),
prop_6: Prop(p6),
) -> ComponentBase(
#(
Computed(p1),
Computed(p2),
Computed(p3),
Computed(p4),
Computed(p5),
Computed(p6),
),
nullable_props,
emits,
)
Define 6 props on a component
See define_component for a full example.
pub fn with_7_nullable_props(
component: ComponentBase(required_props, nullable_props, emits),
prop_1: NullableProp(p1),
prop_2: NullableProp(p2),
prop_3: NullableProp(p3),
prop_4: NullableProp(p4),
prop_5: NullableProp(p5),
prop_6: NullableProp(p6),
prop_7: NullableProp(p7),
) -> ComponentBase(
required_props,
#(
Computed(option.Option(p1)),
Computed(option.Option(p2)),
Computed(option.Option(p3)),
Computed(option.Option(p4)),
Computed(option.Option(p5)),
Computed(option.Option(p6)),
Computed(option.Option(p7)),
),
emits,
)
Define 7 nullable props on a component
See define_component for a full example.
pub fn with_7_props(
component: ComponentBase(required_props, nullable_props, emits),
prop_1: Prop(p1),
prop_2: Prop(p2),
prop_3: Prop(p3),
prop_4: Prop(p4),
prop_5: Prop(p5),
prop_6: Prop(p6),
prop_7: Prop(p7),
) -> ComponentBase(
#(
Computed(p1),
Computed(p2),
Computed(p3),
Computed(p4),
Computed(p5),
Computed(p6),
Computed(p7),
),
nullable_props,
emits,
)
Define 7 props on a component
See define_component for a full example.
pub fn with_8_nullable_props(
component: ComponentBase(required_props, nullable_props, emits),
prop_1: NullableProp(p1),
prop_2: NullableProp(p2),
prop_3: NullableProp(p3),
prop_4: NullableProp(p4),
prop_5: NullableProp(p5),
prop_6: NullableProp(p6),
prop_7: NullableProp(p7),
prop_8: NullableProp(p8),
) -> ComponentBase(
required_props,
#(
Computed(option.Option(p1)),
Computed(option.Option(p2)),
Computed(option.Option(p3)),
Computed(option.Option(p4)),
Computed(option.Option(p5)),
Computed(option.Option(p6)),
Computed(option.Option(p7)),
Computed(option.Option(p8)),
),
emits,
)
Define 8 nullable props on a component
See define_component for a full example.
pub fn with_8_props(
component: ComponentBase(required_props, nullable_props, emits),
prop_1: Prop(p1),
prop_2: Prop(p2),
prop_3: Prop(p3),
prop_4: Prop(p4),
prop_5: Prop(p5),
prop_6: Prop(p6),
prop_7: Prop(p7),
prop_8: Prop(p8),
) -> ComponentBase(
#(
Computed(p1),
Computed(p2),
Computed(p3),
Computed(p4),
Computed(p5),
Computed(p6),
Computed(p7),
Computed(p8),
),
nullable_props,
emits,
)
Define 8 props on a component
See define_component for a full example.
pub fn with_9_nullable_props(
component: ComponentBase(required_props, nullable_props, emits),
prop_1: NullableProp(p1),
prop_2: NullableProp(p2),
prop_3: NullableProp(p3),
prop_4: NullableProp(p4),
prop_5: NullableProp(p5),
prop_6: NullableProp(p6),
prop_7: NullableProp(p7),
prop_8: NullableProp(p8),
prop_9: NullableProp(p9),
) -> ComponentBase(
required_props,
#(
Computed(option.Option(p1)),
Computed(option.Option(p2)),
Computed(option.Option(p3)),
Computed(option.Option(p4)),
Computed(option.Option(p5)),
Computed(option.Option(p6)),
Computed(option.Option(p7)),
Computed(option.Option(p8)),
Computed(option.Option(p9)),
),
emits,
)
Define 9 nullable props on a component
See define_component for a full example.
pub fn with_9_props(
component: ComponentBase(required_props, nullable_props, emits),
prop_1: Prop(p1),
prop_2: Prop(p2),
prop_3: Prop(p3),
prop_4: Prop(p4),
prop_5: Prop(p5),
prop_6: Prop(p6),
prop_7: Prop(p7),
prop_8: Prop(p8),
prop_9: Prop(p9),
) -> ComponentBase(
#(
Computed(p1),
Computed(p2),
Computed(p3),
Computed(p4),
Computed(p5),
Computed(p6),
Computed(p7),
Computed(p8),
Computed(p9),
),
nullable_props,
emits,
)
Define 9 props on a component
See define_component for a full example.
pub fn with_deep(
watch_config: WatchConfig(
values,
has_immediate,
NoDeep,
has_flush,
has_on_track,
has_on_trigger,
has_once,
),
deep: Bool,
) -> WatchConfig(
values,
has_immediate,
WithDeep,
has_flush,
has_on_track,
has_on_trigger,
has_once,
)
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_default(default: default) -> option.Option(default)
Convenience function to make Prop definitions more readable
Prop("name", with_default("John Sumisu"))
pub fn with_emits(
base: ComponentBase(required_props, nullable_props, emits),
emits: List(String),
) -> ComponentBase(required_props, props, new_emits)
Define emits on a component
pub fn with_flush(
watch_config: WatchConfig(
values,
has_immediate,
has_deep,
NoFlush,
has_on_track,
has_on_trigger,
has_once,
),
flush: WatchFlush,
) -> WatchConfig(
values,
has_immediate,
has_deep,
WithFlush,
has_on_track,
has_on_trigger,
has_once,
)
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(
values,
NoImmediate,
has_deep,
has_flush,
has_on_track,
has_on_trigger,
has_once,
),
immediate: Bool,
) -> WatchConfig(
values,
WithImmediate,
has_deep,
has_flush,
has_on_track,
has_on_trigger,
has_once,
)
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(
values,
has_immediate,
has_deep,
has_flush,
has_on_track,
has_on_trigger,
has_once,
),
callback: fn(values, values, 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.
pub fn with_once(
watch_config: WatchConfig(
values,
has_immediate,
has_deep,
has_flush,
has_on_track,
has_on_trigger,
NoOnce,
),
once: Bool,
) -> WatchConfig(
values,
has_immediate,
has_deep,
has_flush,
has_on_track,
has_on_trigger,
WithOnce,
)
Set the once option on a watch
vue.watch_ref(first_name)
|> vue.and_computed(last_name)
|> vue.with_once(True)
|> vue.with_listener(fn(_, _, _) {
// ...
})