Giter Site home page Giter Site logo

masc's Introduction

masc

Masc combines the state management of Bubble Tea with the Vecty view rendering model. The result is a library for building browser applications in Go using The Elm Architecture.

Vecty components are stateless, or, at least, agnostic about how state is managed.

Bubble Tea models are stateful, or, at least, opinionated about how state should be managed.

Masc models look just like Bubble Tea models, except that they return HTML or other components rather than strings when being rendered. This is just like vecty. The vecty rendering engine is used to update the browser.

Masc components look just like Vecty components, except the Render function takes a func(Msg) parameter. This function, called send by convention, is used to send messages to the running program to update its state.

Stateless components implement the Component interface, i.e. have a Render(func(Msg) ComponentOrHTML function.

Models are Components that also implement the Model interface, i.e. have Init() Cmd and Update(Msg) (Model, Cmd) functions.

That is, models are stateful components.

Example

Here's a basic Hello World example.

package main

import (
	"github.com/octoberswimmer/masc"
	"github.com/octoberswimmer/masc/elem"
)

func main() {
	masc.SetTitle("Hello Vecty!")
	m := &PageView{}
	pgm := masc.NewProgram(m)
	_, err := pgm.Run()
	if err != nil {
		panic(err)
	}
}

// PageView is our main page component.
type PageView struct {
	masc.Core
}

func (p *PageView) Init() masc.Cmd {
	return nil
}

func (p *PageView) Update(msg masc.Msg) (masc.Model, masc.Cmd) {
	return p, nil
}

// Render implements the masc.Component interface.
func (p *PageView) Render(send func(masc.Msg)) masc.ComponentOrHTML {
	return elem.Body(
		masc.Text("Hello Vecty!"),
	)
}

Additional examples, including a todo app, are in the example directory. These can be run using wasmserve.

masc's People

Contributors

meowgorithm avatar slimsag avatar muesli avatar caarlos0 avatar cwarden avatar pdf avatar neelance avatar maaslalani avatar knz avatar dmitshur avatar dependabot[bot] avatar bashbunni avatar aymanbagabas avatar dave avatar kiyonlin avatar soypat avatar superpaintman avatar lusingander avatar tbruyelle avatar bzub avatar irevenko avatar inkel avatar nderjung avatar nathanhack avatar pheon-dev avatar ajeetdsouza avatar ilmanzo avatar geodimm avatar michelefiladelfia avatar adjective-object avatar

Stargazers

Szymon Halik avatar

Watchers

 avatar

masc's Issues

update browser when WasmServer recompiles the code on the backend

wonderful stuff and thank you for this.

I ran the example TODO with wasmserve and the first thing I wanted was for the Browser to update automagically.

I wonder if we can send a signal to the wasm running in the browser to force the GUI to update ?


also been playing with https://github.com/tractordev/wanix and figured you might be interested too.

It's a shell and FS inside the browser. All golang and wasm.

It feel like mass and wanix are synergistic. wanix as the OS and mass are the rendering engine.

Let me know what you think :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.