-
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
Dec 9, 2023
1 parent
873bebb
commit 077dc84
Showing
8 changed files
with
122 additions
and
5 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
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,31 @@ | ||
import { TemplateInstance } from '@github/template-parts' | ||
import { parse, EvalAstFactory } from 'jexpr'; | ||
const astFactory = new EvalAstFactory(); | ||
import type { TemplatePart, TemplateTypeInit } from '@github/template-parts'; | ||
|
||
const processor = { | ||
processCallback(_: TemplateInstance, parts: Iterable<TemplatePart>, params: unknown): void { | ||
if (typeof params !== 'object' || !params) return | ||
for (const part of parts) { | ||
const expr = parse(part.expression, astFactory); | ||
part.value = expr?.evaluate(params); | ||
} | ||
} | ||
}; | ||
|
||
|
||
export class LiveStateElement extends HTMLElement { | ||
|
||
templateInstances: TemplateInstance[] = []; | ||
|
||
connectedCallback() { | ||
this.querySelectorAll('template[livestate]').forEach(tpl => { | ||
const instance = new TemplateInstance((tpl as HTMLTemplateElement), { person: { firstName: 'Bob', lastName: 'Jones' } }, processor); | ||
this.templateInstances.push(instance); | ||
this.appendChild(instance); | ||
}); | ||
} | ||
|
||
} | ||
|
||
window.customElements.define('live-state', LiveStateElement); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -4,7 +4,10 @@ | |
"build": "tsc && vite build" | ||
}, | ||
"dependencies": { | ||
"@github/template-parts": "^0.5.4", | ||
"jexpr": "^1.0.0-pre.4", | ||
"lit": "^2.4.0", | ||
"stampino": "[email protected]:jogibear9988/stampino.git", | ||
"phx-live-state": "file:../../phx-live-state" | ||
}, | ||
"devDependencies": { | ||
|
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
6 changes: 6 additions & 0 deletions
6
lib/livestate_testbed_web/templates/page/markup_test.html.heex
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,6 @@ | ||
<live-state url={@url} topic="people"> | ||
<template> | ||
{{person.firstName}} {{person.lastName}} | ||
</template> | ||
</live-state> | ||
|