the-fun-framework icon indicating copy to clipboard operation
the-fun-framework copied to clipboard

[QUESTION] Reusable Components

Open go4cas opened this issue 2 years ago • 1 comments

Very interesting concept! How would one create reusable named components?

go4cas avatar Jun 12 '23 07:06 go4cas

Nothing yet! I have some ideas on this, but it requires a bit of fiddling, truth be told.

I'm leaning towards Web Components + HTML string templates being the way to go.

Using Vite, it might look something like:

<!-- counter.component.html -->
<button data-on-click="updateCount()">Add one to {{count.value}}</button>
/* counter.component.ts */
import template from "./counter.component.html?raw";
function Counter() {
  let count = createState(
    0
  );

  function updateCount() {
    count.value++;
  }

  return {
    count,
    updateCount
  }
}

Counter.selector = "app-counter";
Counter.template = template;
registerComponent(Counter);
/* app.component.ts */
function App() {
}

// Register with the same name as `data-island-comp`
App.selector = "app-app";
App.template = `<app-counter></app-counter>`;
registerComponent(App);
render()

crutchcorn avatar Jun 18 '23 08:06 crutchcorn