Skip to content

Commit

Permalink
Add working Example
Browse files Browse the repository at this point in the history
  • Loading branch information
vunam committed Aug 12, 2024
1 parent e09ba82 commit 9ea92bf
Show file tree
Hide file tree
Showing 7 changed files with 1,829 additions and 89 deletions.
9 changes: 9 additions & 0 deletions example/assets/ChildFrame.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<body>
<h1>Child Frame</h1>

<button>Increment counter</button>
<script type="module" src="/child.js"></script>
</body>
</html>
11 changes: 11 additions & 0 deletions example/assets/child.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { ChildFrame } = require("../../build/index");



(function() {
const frameEvents = new ChildFrame();

document.querySelector("button").addEventListener("click", function () {
frameEvents.run.updateCounter();
});
})();
13 changes: 13 additions & 0 deletions example/assets/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<body>

<h1>Parent Frame</h1>
<p>Counter: <span id="counter">0</span></p>

<iframe id="childFrame" src="./ChildFrame.html?_origin=localhost:3030&_placement=TEST" width="500" height="500"></iframe>

<script type="text/javascript" src="/parent.js"></script>

</body>
</html>
31 changes: 31 additions & 0 deletions example/assets/parent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* eslint-disable */

const { ParentFrame } = require("../../build/index");

(function() {
const state = {
counter: 0,
};

console.log('test')
const element = document.getElementById("childFrame");
console.log(element)

new ParentFrame({
child: document.getElementById("childFrame"),
methods: {
updateCounter: function () {
state.counter = state.counter++;
this.send("counterUpdated", {
counter: state.counter,
});

const counterElement = document.getElementById("counter");
counterElement.innerHTML = state.counter;
console.log('!!!')
},
},
listeners: ["counterUpdated"],
scripts: [],
});
})();
22 changes: 22 additions & 0 deletions example/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable */

const path = require('path');

module.exports = {
entry: {
parent: path.resolve(__dirname, './assets/parent.js'),
child: path.resolve(__dirname, './assets/child.js'),
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'assets/build'),
},
mode: 'production',
target: "web",
devServer: {
static: {
directory: path.join(__dirname, 'assets'),
},
port: 3030,
},
};
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@
"ts-jest": "^29.1.5",
"ts-node": "^10.9.2",
"tslib": "^2.6.3",
"typescript": "^5.5.3"
"typescript": "^5.5.3",
"webpack": "^5.93.0",
"webpack-dev-server": "^5.0.4"
},
"dependencies": {},
"config": {
Expand Down
Loading

0 comments on commit 9ea92bf

Please sign in to comment.