Skip to content

Commit f34b51d

Browse files
committed
feat(JS lib): add a client JS lib for the Communicator
similar to trame-client js-api, trame-iframe js-api provides an agnostic library that can be installed in a regular JS project. trame-iframe js-api could be installed in a host application (could be react/streamlit/vue/... based) to proxy the trame API calls through the iframe to the Communicator and the trame application. The goal is to replicate the trame-client js-api features to make it transparent to the consumer code. API: - trame.state.set - trame.state.update - trame.state.watch - trame.trigger This is still possible to directly interact with the Communicator from an host application by manually sending/listening to events.
1 parent 885bbbe commit f34b51d

File tree

9 files changed

+5732
-1
lines changed

9 files changed

+5732
-1
lines changed

js-lib/.eslintrc.cjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* eslint-env node */
2+
require("@rushstack/eslint-patch/modern-module-resolution");
3+
4+
module.exports = {
5+
root: true,
6+
extends: [
7+
"eslint:recommended",
8+
"@vue/eslint-config-prettier",
9+
],
10+
env : {
11+
browser : true,
12+
es6 : true,
13+
},
14+
rules : {
15+
"no-unused-vars" : 2,
16+
"no-undef" : 2
17+
},
18+
parserOptions: {
19+
sourceType: "module",
20+
ecmaVersion: "latest",
21+
},
22+
};

js-lib/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

js-lib/LICENSE

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Apache Software License 2.0
2+
3+
Copyright (c) 2024, Kitware Inc.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.

js-lib/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// const trame = new Trame({ iframe });
2+
// await trame.connect({ application: 'trame' });
3+
4+
// State handing
5+
trame.state.set("a", 5);
6+
console.log(trame.state.get("b"));
7+
trame.state.update({
8+
a: 1,
9+
b: 2,
10+
});
11+
12+
// Method call on Python
13+
const result = await trame.trigger("name", [arg_0, arg_1], { kwarg_0: 1, kwarg_1: 2 });
14+
15+
// TODO - state watching
16+
trame.state.watch(["a"], (a) => {
17+
console.log(`a changed to ${a}`);
18+
})

0 commit comments

Comments
 (0)