Skip to content

Commit

Permalink
feat(JS lib): add a client JS lib for the Communicator
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bourdaisj committed Dec 6, 2024
1 parent 885bbbe commit 76fa781
Show file tree
Hide file tree
Showing 9 changed files with 5,743 additions and 1 deletion.
22 changes: 22 additions & 0 deletions js-lib/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-env node */
require("@rushstack/eslint-patch/modern-module-resolution");

module.exports = {
root: true,
extends: [
"eslint:recommended",
"@vue/eslint-config-prettier",
],
env : {
browser : true,
es6 : true,
},
rules : {
"no-unused-vars" : 2,
"no-undef" : 2
},
parserOptions: {
sourceType: "module",
ecmaVersion: "latest",
},
};
1 change: 1 addition & 0 deletions js-lib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
15 changes: 15 additions & 0 deletions js-lib/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Apache Software License 2.0

Copyright (c) 2024, Kitware Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
18 changes: 18 additions & 0 deletions js-lib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// const trame = new Trame({ iframe });
// await trame.connect({ application: 'trame' });

// State handing
trame.state.set("a", 5);
console.log(trame.state.get("b"));
trame.state.update({
a: 1,
b: 2,
});

// Method call on Python
const result = await trame.trigger("name", [arg_0, arg_1], { kwarg_0: 1, kwarg_1: 2 });

// TODO - state watching
trame.state.watch(["a"], (a) => {
console.log(`a changed to ${a}`);
})
Loading

0 comments on commit 76fa781

Please sign in to comment.