Operations and Tasks are Total's features which can be used in many different cases. Operation is something like global function in your app but with some extra functionality. Task has multiple smaller functions which can be called separatly from that task or even outside of that task. You can even chain them inside single task to create complex recursive flows.
Operations are global functions with some extra functionality. They are often used as alternative way to handle client requests or used as wrappers.
Declare:
Operations are usually stored in operations
directory inside root of your application. To declare new operation you need to use global function NEWOPERATION()
. Function takes two required and four optional arguments:
$
that will be executed when operation is called .CONVERT()
on background. Converted values are stored in $.filter
object.To make operation successful use one of these functions $.success()
, $.done()
or $.callback()
.
To make operation un-successful (throw error in callback) you can use $.invalid()
.
*Required
Usage:
After declaring your operation you can simply execute it with OPERATION()
. Function has two required and three optional arguments:
$.value
.*Required
You can also call operation directly from your ROUTE()
:
Multioperation:
To run multiple operations in your code you can use global function RUN()
. This function has two required and four optional arguments:
RUN()
function support multiple declaration syntaxes for operations:
$.value
in each operation.*Required
Response value in your callback function will be an object of all operation's responses. If you want only specific response you can name of that operation as fourth argument:
This code bellow is equivalent of RUN()
's multioperation that is above but its targeted for ROUTE()
:
After user hits GET /operations/
route, operations first
, second
and third
will be executed and user will get response (or error) from second
operation because it has (response)
.
Tasks are very versatile because they can execute infinitely between themself. Tasks are great solution for your simple or complex processes.
Declare:
All tasks are usually stored in tasks
directory inside root of your Total.js application. To declare new operation use global function NEWTASK()
:
push
argument that is used for adding more "steps" to your task.*Required
Useful $
methods for tasks:
$.end(value)
- Ends task and execute callback declared with TASK()
.$.end2(value)
- Return $.end(value)
wrapped in function (use this as callback function).$.next(step)
- Call next task "step".$.next2(step)
- Return $.next(step)
wrapped in function (use this as callback function).$.success()
and $.invalid()
are also valid methods in task builder.Usage:
To execute your tasks use global function TASK()
:
/
('Add/init'
for example).error
and response
objects (depends on task's result). Callback is called after executing $.end()
method in your task.Controller
or $
*Required