Skip to content

getty104/ruby-wasm-vdom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ruby-wasm-vdom

This is a library for using virtual dom in ruby with web assembly.

How to use

You can use this library by adding the following to your html file.

<html>
  <head>
  </head>
  <body>
    <div id="app"></div>
    <script src="https://getty104.github.io/ruby-wasm-vdom/index.js"></script>
    <script type="text/ruby">
      state = {
        count: 0,
      }

      actions = {
        increment: ->(state, value) {
        state[:count] += 1
        }
      }

      view = ->(state, actions) {
        h(:div, {}, [
          h(:button, { onclick: ->(e) { actions[:increment].call(state, nil) } }, ['Click me!']),
          h(:p, {}, ["Count is #{state[:count]}"])
        ])
      }

      RubyWasmVdom::App.new(
        el: "#app",
        state:,
        view:,
        actions:
      )
    </script>
  </body>
</html>

You can also write vdom with like jsx signature with DomParser

<html>
  <head>
  </head>
  <body>
    <div id="app"></div>
    <script src="https://getty104.github.io/ruby-wasm-vdom/index.js"></script>
    <script type="text/ruby">
      state = {
        count: 0,
      }

      actions = {
        increment: ->(state, value) {
        state[:count] += 1
        }
      }

      view = ->(state, actions) {
        eval RubyWasmVdom::DomParser.parse(<<-DOM)
          <div>
            <button onclick='{->(e) { actions[:increment].call(state, nil) } }'>Click me!</button>
            <p>{"Count is #{state[:count]}"}</p>
          </div>
        DOM
      }

      RubyWasmVdom::App.new(
        el: "#app",
        state:,
        view:,
        actions:
      )
    </script>
  </body>
</html>

Examples

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages