Trame iframe library for plain JS
This library aims to simplify interaction between a trame application living inside an iframe and its iframe parent.
This work is inspired by the official trame-client js lib
Examples
Usage
First you need to grab the iframe that contains your trame application.
import ClientCommunicator from "@kitware/trame-iframe";
const iframe = document.getElementById("trame_app");
const iframe_url = "http://localhost:3000";
const trame = new ClientCommunicator(iframe, iframe_url);
trame.state.set("a", 2);
trame.state.set('b', 3);
trame.state.update({
a: 2.5,
b: 3.5,
c: 4.5,
})
console.log(trame.state.get("c"));
console.log(trame.state.get('a'));
trame.state.watch(
["a", "b", "c"],
(a, b, c) => {
console.log(`a(${a}) or b(${b}) or c(${c}) have changed`);
}
);
trame.trigger("name", ['arg_0', 'arg_1'], { kwarg_0: 1, kwarg_1: 2 });