Skip to content

Commit 99c4464

Browse files
committed
add examples
1 parent d974d9f commit 99c4464

File tree

18 files changed

+1390
-0
lines changed

18 files changed

+1390
-0
lines changed

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
node_modules
3+
4+
/.nyc_output
5+
/coverage
6+
/playground
7+
/.idea
8+
/.cache
9+
build
10+
/dist
11+
/src/**/*.js
12+
/test/**/*.js
13+
/example/**/*.js
14+
*.map
15+
*.jsx
16+
/tool/**/*.js
17+
/temp

.prettierrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"tabWidth": 2,
3+
"printWidth": 120,
4+
"semi": true,
5+
"singleQuote": true,
6+
"bracketSpacing": false,
7+
"arrowParens": "always",
8+
"quoteProps": "consistent"
9+
}

package.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "server-example",
3+
"version": "0.0.2",
4+
"description": "ticlo server example",
5+
"scripts": {
6+
"basic-example": "ts-node src/basic-example/main.ts",
7+
"route-example": "ts-node src/route-example/main.ts",
8+
"multi-server-example": "ts-node src/multi-server-example/main.ts",
9+
"custom-function-example": "ts-node src/custom-function-example/main.ts"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "git+https://github.com/ticlo/server-example.git"
14+
},
15+
"author": "",
16+
"license": "Apache-2.0",
17+
"dependencies": {
18+
"@ticlo/core": "^0.0.4",
19+
"@ticlo/express": "^0.0.4",
20+
"@ticlo/node": "^0.0.4",
21+
"@types/express": "^4.17.2",
22+
"express": "^4.17.1",
23+
"ts-node": "^8.6.2",
24+
"typescript": "^3.7.5",
25+
"moment": "^2.24.0"
26+
},
27+
"devDependencies": {
28+
"prettier": "^1.19.1"
29+
}
30+
}

src/basic-example/example.ticlo

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"#is": "",
3+
"add": {
4+
"#is": "add",
5+
"0": 2,
6+
"1": 3,
7+
"@b-p": [
8+
"0",
9+
"1",
10+
"output"
11+
],
12+
"@b-xyw": [
13+
88.796875,
14+
65,
15+
150
16+
]
17+
},
18+
"add0": {
19+
"#is": "add",
20+
"@b-p": [
21+
"0",
22+
"1",
23+
"output"
24+
],
25+
"@b-xyw": [
26+
321.796875,
27+
91,
28+
150
29+
],
30+
"~0": "##.add.1",
31+
"~1": "##.add.output"
32+
}
33+
}

src/basic-example/main.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Express from 'express';
2+
import {Root} from '@ticlo/core';
3+
import {FileJobLoader} from '@ticlo/node';
4+
import {connectTiclo, getEditorUrl} from '@ticlo/express';
5+
6+
// save load jobs from the the same folder
7+
Root.instance.setLoader(new FileJobLoader('./src/basic-example'));
8+
9+
let app = Express();
10+
connectTiclo(app, '');
11+
12+
app.listen(8010);
13+
14+
console.log(getEditorUrl('ws://127.0.0.1:8010', 'example'));
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {Functions, BaseFunction} from '@ticlo/core';
2+
3+
// sort input string and output an array
4+
class SortStringFunction extends BaseFunction {
5+
run(): any {
6+
let delay = this._data.getValue('delay');
7+
if (delay > 0) {
8+
return new Promise((resolve) => {
9+
setTimeout(() => {
10+
this._data.output(delay);
11+
resolve();
12+
}, delay * 1000);
13+
});
14+
}
15+
}
16+
}
17+
18+
Functions.add(
19+
SortStringFunction,
20+
{
21+
name: 'delay',
22+
icon: 'fas:bomb', // icon from font awesome
23+
properties: [
24+
{name: 'delay', type: 'number'},
25+
{name: 'output', type: 'number', readonly: true}
26+
]
27+
},
28+
'my' // namespace for the function
29+
);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"#is": "",
3+
"delay": {
4+
"#is": "my:delay",
5+
"#more": [],
6+
"@b-p": [
7+
"delay",
8+
"output"
9+
],
10+
"@b-xyw": [
11+
349.796875,
12+
176,
13+
243
14+
],
15+
"delay": 5
16+
},
17+
"get-time": {
18+
"#is": "my:get-time",
19+
"@b-p": [
20+
"output"
21+
],
22+
"@b-xyw": [
23+
624.796875,
24+
331,
25+
243
26+
],
27+
"~#call": "##.delay.output"
28+
},
29+
"sort-string": {
30+
"#is": "my:sort-string",
31+
"0": "b",
32+
"1": "a",
33+
"@b-p": [
34+
"0",
35+
"1",
36+
"output"
37+
],
38+
"@b-xyw": [
39+
24.796875,
40+
179,
41+
234
42+
]
43+
}
44+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import {Functions, BaseFunction} from '@ticlo/core';
2+
3+
// sort input string and output an array
4+
class SortStringFunction extends BaseFunction {
5+
run(): any {
6+
let len = this._data.getLength();
7+
if (!(len >= 0)) {
8+
len = 2;
9+
}
10+
let arr: any[] = [];
11+
for (let i = 0; i < len; ++i) {
12+
let val = this._data.getValue(String(i));
13+
if (typeof val !== 'string') {
14+
// invalid input
15+
this._data.output(undefined);
16+
return;
17+
} else {
18+
arr.push(val);
19+
}
20+
}
21+
arr.sort();
22+
this._data.output(arr);
23+
}
24+
}
25+
26+
Functions.add(
27+
SortStringFunction,
28+
{
29+
name: 'sort-string',
30+
icon: 'fas:sort-alpha-down', // icon from font awesome
31+
properties: [
32+
{
33+
// input 0 1 2 3 .... as string
34+
name: '',
35+
type: 'group',
36+
defaultLen: 2,
37+
properties: [{name: '', type: 'string', visible: 'high'}]
38+
},
39+
{name: 'output', type: 'array', readonly: true}
40+
]
41+
},
42+
'my' // namespace for the function
43+
);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Express from 'express';
2+
import {Root} from '@ticlo/core';
3+
import {FileJobLoader} from '@ticlo/node';
4+
import {connectTiclo, getEditorUrl} from '@ticlo/express';
5+
6+
// import the function
7+
import './async-function';
8+
import './group-input-function';
9+
import './oncall-function';
10+
11+
// save load jobs from the the same folder
12+
Root.instance.setLoader(new FileJobLoader('./src/custom-function-example'));
13+
14+
let app = Express();
15+
connectTiclo(app, '');
16+
17+
app.listen(8014);
18+
19+
console.log(getEditorUrl('ws://127.0.0.1:8014', 'example'));
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import {Functions, BaseFunction} from '@ticlo/core';
2+
import Moment from 'moment';
3+
4+
// sort input string and output an array
5+
class GetTimeFunction extends BaseFunction {
6+
run(): any {
7+
this._data.output(Moment());
8+
}
9+
}
10+
11+
Functions.add(
12+
GetTimeFunction,
13+
{
14+
name: 'get-time',
15+
icon: 'fas:clock', // icon from font awesome
16+
mode: 'onCall', // by default run function only when #call is triggered
17+
properties: [{name: 'output', type: 'date', readonly: true}]
18+
},
19+
'my' // namespace for the function
20+
);

0 commit comments

Comments
 (0)