All Projects → inamiy → VTree

inamiy / VTree

Licence: MIT license
VirtualDOM for Swift (iOS, macOS)

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to VTree

Hydux
A light-weight type-safe Elm-like alternative for Redux ecosystem, inspired by hyperapp and Elmish
Stars: ✭ 216 (+142.7%)
Mutual labels:  virtual-dom
SwiftElm
Reactive + Automaton + VTree in Swift, inspired by Elm.
Stars: ✭ 97 (+8.99%)
Mutual labels:  virtual-dom
boba
A lightweight, modular CSS framework.
Stars: ✭ 47 (-47.19%)
Mutual labels:  flexbox
Ioing
Implement the solutions of performance improvement and componentization for your SPA (single page application) products with this Progressive Web App Development Engine.
Stars: ✭ 224 (+151.69%)
Mutual labels:  virtual-dom
Ng Vdom
(Developer Preview) A virtual-DOM extension for Angular, also work as React bridge.
Stars: ✭ 249 (+179.78%)
Mutual labels:  virtual-dom
wui builder
A dart library for building user interfaces for the web, inspired by reactjs.
Stars: ✭ 21 (-76.4%)
Mutual labels:  virtual-dom
Preact Worker Demo
Demo of preact rendering an entire app in a Web Worker.
Stars: ✭ 204 (+129.21%)
Mutual labels:  virtual-dom
whistle
Experiment to build single page apps in Elixir
Stars: ✭ 52 (-41.57%)
Mutual labels:  virtual-dom
Live
Live views and components for golang
Stars: ✭ 251 (+182.02%)
Mutual labels:  virtual-dom
stacks-11ty
Open source 11ty theme with personality
Stars: ✭ 21 (-76.4%)
Mutual labels:  flexbox
Respo
A virtual DOM library built with ClojureScript, inspired by React and Reagent.
Stars: ✭ 230 (+158.43%)
Mutual labels:  virtual-dom
Superviews.js
Template engine targeting incremental-dom
Stars: ✭ 242 (+171.91%)
Mutual labels:  virtual-dom
Chartboard
Simple dashboard to show widget chart
Stars: ✭ 23 (-74.16%)
Mutual labels:  flexbox
Asm Dom
A minimal WebAssembly virtual DOM to build C++ SPA (Single page applications)
Stars: ✭ 2,604 (+2825.84%)
Mutual labels:  virtual-dom
vfin
🦈 GUI framework agnostic virtual DOM library
Stars: ✭ 17 (-80.9%)
Mutual labels:  virtual-dom
Panel
Web Components + Virtual DOM: web standards for powerful UIs
Stars: ✭ 206 (+131.46%)
Mutual labels:  virtual-dom
react-twitter-clone
MaterialUI (for icons and flexbox), React (for building), CSS (for styling), Firebase (for deploying online), npm (for animations in tweet)
Stars: ✭ 25 (-71.91%)
Mutual labels:  flexbox
11r
America's favorite Eleventy blog template.
Stars: ✭ 135 (+51.69%)
Mutual labels:  flexbox
csslayout
A collection of popular layouts and patterns made with CSS. Now it has 100+ patterns and continues growing!
Stars: ✭ 7,297 (+8098.88%)
Mutual labels:  flexbox
core
Server side rendering with The Elm Architecture in Deno
Stars: ✭ 16 (-82.02%)
Mutual labels:  virtual-dom

VTree

VirtualDOM for Swift (iOS, macOS), inspired by Matt-Esch/virtual-dom and elm-lang/virtual-dom.

See inamiy/SwiftElm for practical use.

Pseudocode

// ===== VTree.framework =====

protocol VTree {
    ...
    var children: [VTree] { get }
}

struct VView: VTree { ... }   // Virtual UIView
struct VLabel: VTree { ... }  // Virtual UILabel
...

// ========= Example =========

typealias State = Int  // can be any type

// Generate immutable `VTree` from `State`.
func render(state: State) -> VTree {
    return VView(children: [
        VLabel(text: "\(state)")
    ])
}

// Initialize `State`, `VTree`, and `UIView`.
var state = 0
var tree = render(state)
var view = createView(tree)

// Update logic: Timer updates `state` and re-render.
timer(1) {
    state += 1
    let newTree = render(state)
    let patch = diff(old: tree, new: newTree)
    view = apply(patch: patch, to: view)
}

This is an example of timer updating a count in view.label.

Unlike setting view.label.text = "\(state)" or any data bindings e.g. reactive programming that directly mutates variables from all over the place, VTree minimizes such side-effects by:

  1. Generating an immutable VTree from a single state
  2. Calculating a patch using an efficient diff algorithm, and
  3. Mutating a view only by calling apply

This seems like too much calculation for just tweaking a single variable, but it eventually prevents us from making stupid side-effects that is the 99% cause of our app's bugs.

Above code is just a pseudocode for simple protocol VTree. For better type-safety, protocol VTree will require associatedtype and also type-erasure techinique.

Please see Tests/DiffSpec.swift for more examples.

Metaprogramming with Sourcery

VTree uses Sourcery as Swift template metaprogramming engine to cover transcripting that elm-lang/core does when converting enum MyMsg to JavaScript.

By using Scripts/generate-message.sh, VTree will support AutoMessage to auto-generate extension MyMsg: Message. This is a requisite for VTree when interacting Cocoa events with user's enum Msg.

# Usage: ./generate-message.sh <source_dir> <code-generated-dir>
$ ./path/to/VTree/Scripts/generate-message.sh ./Demo/Sources ./Demo/Sources/CodeGenerated/

So that user can simplify enum MyMsg as:

enum MyMsg: AutoMessage {
    // NOTE: `MessageContext` is always required when enum-case (value constructor) requires arguments.
    case tap(GestureContext)
    case pan(PanGestureContext)
}

Feature

  • Handle more complicated cocoa events e.g. mouse, gesture, keyboard. MessageContext
  • Add better layouting system, e.g. CSS Flexbox. inamiy/Flexbox
  • Create more VTree concrete types for virtual UI***View.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].