module salix::Core
Usage
import salix::Core;
Source code
http://github.com/usethesource/salix-core/src/main/rascal/salix/Core.rsc
Dependencies
import salix::Node;
import List;
import String;
import IO;
import lang::json::IO;
data Handle
data Handle
= handle(int id, list[int] maps = [])
;
Handles represent (encoded) functions to decode events. id: identifies the decoder function (e.g., of type Msg(int)) maps: identifies the active mappers for this handle.
alias Encoding
tuple[int id, map[int, value] from, map[value, int] to, map[int, value] closures]
function switchTo
void switchTo(str appId)
function switchFrom
void switchFrom(str appId)
function _encode
int _encode(value x)
function _partial
&T(&V) _partial(list[value] key, &T(&V) closure)
function partial
&T(&V) partial(&T(&U0, &V) f, &U0 u0)
&T(&V) partial(&T(&U0, &U1, &V) f, &U0 u0, &U1 u1)
&T(&V) partial(&T(&U0, &U1, &U2, &V) f, &U0 u0, &U1 u1, &U2 u2)
&T(&V) partial(&T(&U0, &U1, &U2, &U3, &V) f, &U0 u0, &U1 u1, &U2 u2, &U3 u3)
function _decode
&U _decode(int funcId, type[&U] _)
default &U _decode(int funcId, type[&U] _)
function encode
Handle encode(value x)
function decode
&T decode(Handle h, type[&T] t)
&T decode(int funcId, type[&T] t)
function printNodeStack
void printNodeStack()
Print out the current node stack for debugging.
function add
void add(Node h)
Basic stack management functions.
function addNode
void addNode(Node h)
function push
void push(list[Node] l)
function top
list[Node] top()
function pop
list[Node] pop()
function initialize
tuple[list[Cmd], &T] initialize(&T() init, void(&T) view)
Initialize viewContext for an initial model, so that cmds are properly mapped.
function render
Node render(&T model, void(&T) block)
Node render(void() block)
Render turns void returning views for a model &T into an Node node.
function withExtra
void withExtra(map[str, value] stuff, void() block)
function build
void build(list[value] vals, str tagName)
The basic build function to construct html elements on the stack. The list of argument values can contain any number of Attr values. The last argument (if any) can be a blouitck, an Node node, or a value. In the latter case it is converted to a txt node.
function _text
void _text(value v)
Create a text node from an arbitrary value.
data Sub
data Sub
= subscription(str name, Handle handle, map[str, value] args = ())
;
Subs are like events: they are sent to JS, and messages are sent back.
function timeEvery
Sub timeEvery(Msg(int) int2msg, int interval)
Smart constructors for constructing encoded subscriptions.
alias Subs
list[Sub](&T)
function noSubs
list[Sub] noSubs(&T _)
data Cmd
data Cmd
= command(str name, Handle handle, map[str,value] args = ())
;
Commands represent actions that need to be performed at the client.
function do
void do(Cmd cmd)
function execute
tuple[list[Cmd], &T] execute(Msg msg, &T(Msg, &T) update, &T model)
tuple[list[Cmd], &T] execute(&T() init)
function random
Cmd random(Msg(int) f, int from, int to)
Smart constructors for constructing encoded commands.
function setFocus
Cmd setFocus(Msg() f, str id)
data Hnd
data Hnd
= handler(str name, Handle handle, map[str,value] args = ())
;
alias Parser
Msg(str,Handle,map[str,value])
function params2msg
Msg params2msg(map[str, value] params, Parser parse)
Convert request parameters to a Msg value. Active mappers at path
transform the message according to f.
function toHandle
Handle toHandle(map[str, value] params)
Parse request parameters into a Handle.
function toMaps
list[int] toMaps(str x)
function parseMsg
Msg parseMsg("nothing", Handle h, map[str, value] p)
Msg parseMsg("string", Handle h, map[str,value] p)
Msg parseMsg("boolean", Handle h, map[str, value] p)
Msg parseMsg("integer", Handle h, map[str, value] p)
Msg parseMsg("real", Handle h, map[str,value] p)
Msg parseMsg("values", Handle h, map[str,value] p)
alias XY
tuple[int x, int y]
alias MouseXY
tuple[XY client, XY movement, XY offset, XY page, XY screen]
function parseMsg
Msg parseMsg("mouseXY", Handle h, map[str,value] p)
Msg parseMsg("json", Handle h, map[str, value] p)
function applyMaps
Msg applyMaps(Handle h, Msg msg)
function withMapper
&T withMapper(Msg(Msg) f, &T() block)
function mapSubs
list[Sub] mapSubs(Msg(Msg) f, &T t, list[Sub](&T) subs)
function mapCmds
&T mapCmds(Msg(Msg) f, Msg msg, &T t, &T(Msg, &T) upd)
&T mapCmds(Msg(Msg) f, &T() init)
function mapView
void mapView(Msg(Msg) f, &T t, void(&T) block)
Record mapper to transform messages produced in block according f.
function _reset
void _reset()