Members
# static constant command$
Primary fork/bisect stream for indivual commands.
attached to a pubsub
stemming from this stream. The
topic
function used to alert downstream handlers is a
simple lookup of the sub$
key of the command
# static constant multiplex
Handles Collections (array) of Commands ("Tasks") which require ordered choreography and/or have a dependency on some (a)sync data produced by a user interaction.
Subtasks:
Subtasks are the way you compose tasks. Insert a Task and the spool will unpack it in place (super -> sub order preserved) A Subtask must be defined as a unary function that accepts an accumulator object and returns a Task, e.g.:
PSEUDO
// { C: Command }
// ( { A: Accumulator }: Object ) => [{C},{C}]: Subtask
let someSubtask = ({A}) => [{C}, {C}, ({A})=>[{C},{C}], ...]
Example
// subtask example:
let subtask1 = acc => [
{ sub$: "acc"
, args: { data: acc.data } },
{ sub$: "route"
, args: { route: { href: acc.href } } }
]
// task
let task = [
{ args: { href: "https://my.io/todos" } }, // acc init
{ sub$: "fetch"
, args: ({ href }) => fetch(href).then(r => r.json())
, erro: (acc, err) => ({ sub$: "cancel", args: err })
, reso: (acc, res) => ({ data: res }) },
acc => subtask1(acc), // subtask reference
{ sub$: "FLIP" , args: "done" }
]
Ad-hoc stream injection Example
import { stream } from "@thi.ng/rstream"
import { map, comp } from "@thi.ng/transducers"
// ad-hoc stream
let login = stream().subscribe(comp(
map(x => console.log("login ->", x)),
map(({ token }) => loginToMyAuth(token))
))
// subtask
let subtask_login = ({ token }) => [
{ sub$: login // <- stream
, args: () => ({ token }) } // <- use acc
]
// task
let task = [
// no sub$, just pass data
{ args: { href: "https://my.io/auth" } },
{ sub$: login , args: () => "logging in..." },
{ sub$: "AUTH"
, args: ({ href }) => fetch(href).then(r => r.json())
, erro: (acc, err) => ({ sub$: "cancel", args: err })
, reso: (acc, res) => ({ token: res }) },
acc => subtask_login(acc),
{ sub$: login , args: () => "log in success" }
]
# static constant out$
Primary user-land READ stream. For attaching handlers for responding to emmitted Commands
# static constant run$
User-land event dispatch stream
This stream is directly exposed to users. Any one-off
Commands next
ed into this stream are sent to the
command$
stream. Arrays of Commands (Tasks) are sent to
the task$
stream.
TODO: add examples,beforeunload
event handler within #4
(orphan): SEE https://youtu.be/QQukWZcIptM and enable
ctx.run.cancel() via external or internal events
(e.g., popstate / { sub$: "cancel" })
# static constant task$
Task stream that handles Arrays of Commands. Dispatches
to multiplex
er (the heart of spule
)
# inner result
If some signature needs to deal with both Promises and non-Promises, non-Promises are wrapped in a Promise to "lift" them into the proper context for handling