-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chris Nelson
committed
Oct 12, 2023
1 parent
d9a5169
commit c89e365
Showing
11 changed files
with
83 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { html, css, LitElement } from 'lit' | ||
import { customElement, property, query } from 'lit/decorators.js' | ||
import { liveState, liveStateConfig } from 'phx-live-state'; | ||
|
||
/** | ||
* An example element. | ||
* | ||
* @slot - This element has a slot | ||
* @csspart button - The button | ||
*/ | ||
@customElement('wasm-test') | ||
@liveState({topic: 'wasm', properties: ['foo'], events: {send: ['increaseFoo']}}) | ||
export class JoinParamsElement extends LitElement { | ||
|
||
@property({attribute: 'the-url'}) | ||
@liveStateConfig('url') | ||
theUrl: string = "foo"; | ||
|
||
@property() | ||
// @liveStateProperty() | ||
foo: string = ''; | ||
|
||
render() { | ||
return html` | ||
<div> | ||
${this.foo} | ||
</div> | ||
<button @click=${this.increaseFoo}>Increase the foo!</button> | ||
` | ||
} | ||
|
||
increaseFoo() { | ||
this.dispatchEvent(new CustomEvent('increaseFoo', {detail: {foo: 'even more foo!'}})); | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'wasm-test': JoinParamsElement | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<wasm-test the-url={@url}></wasm-test> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
manifest = %{wasm: [ %{ path: "priv/wasm/dist/plugin.wasm" } ] } | ||
{:ok, plugin} = Extism.Plugin.new(manifest, true) | ||
{:ok, initial_state} = Extism.Plugin.call(plugin, "init", "") | ||
IO.inspect(initial_state) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
|
||
export function foo() { | ||
let input = JSON.parse(Host.inputString()); | ||
const output = { | ||
stuff: input.stuff + " and moar" | ||
} | ||
Host.outputString(JSON.stringify(output)); | ||
} | ||
import { wrap } from "./wrap"; | ||
|
||
export const init = wrap(function() { | ||
return { foo: "bar"}; | ||
}); | ||
|
||
export const increaseFoo = wrap(function(payload, state) { | ||
return { foo: state.foo + payload.foo}; | ||
}); | ||
|
||
// export const increaseFoo({}) { | ||
|
||
// } | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export function wrap(f) { | ||
return function() { | ||
const inputStr = Host.inputString(); | ||
let output | ||
if (inputStr != "") { | ||
const args = JSON.parse(inputStr); | ||
output = f(...args); | ||
} else { | ||
output = f(); | ||
} | ||
Host.outputString(JSON.stringify(output)); | ||
} | ||
} |