Code Monkey home page Code Monkey logo

live.js's Introduction

live.js

A lightweight pure javascript framework made just for learn and fun.

  • ⚠️ Reasons to not use it in production or web dev:

    • Not performant.
    • Made just for learning and fun purposes.
    • Will not be mantained.
    • May have bugs.
    • Doesn't react properly to state changes while already rendering something.
    • Its just a proof of concept.
  • Features:

    • It's capable of rendering html out of template literals using DOMParser
    • It's capable of creating states with the help of template literals to integrate it into the dom.
    • It's capable to react to state changes using the live method.
    • Can't render custom components, unless you use it like:
      function myComp(message: string) {
        return html`<span>Custom component ${message}</span>`;
      }
      
      function app() {
        return html`<div className="app">${app("Hello world")}</div>`
      }
      ⚠️It will work in the next commit, so it doesn't work yet. But this would be the way to use custom components.

Example of a notes app

  • Features:
    • Add notes
    • Show/hide notes
import { html, useState, live } from "./lib/index.js";

export function app() {
    const todoList = useState<string[]>([]);
    const textInput = useState("");
    const showNotes = useState(false);

    const handleAddNote = function() {
        const value = textInput.get();
        todoList.set(todoList => [...todoList, value]);
        textInput.set("");
    }

    return html`
    <div className="app">
        <div>
            <label>Type your notes:</label>
            <input type="text" onchange=${(e: any) => textInput.set(e.target.value)} value=${textInput} />
            <button type="button" onclick=${handleAddNote}>Add</button>
            <button type="button" onclick=${(e: any) => showNotes.set(show => !show)}>${live(() => html`<span>${showNotes.get() ? "Hide notes" : "Show notes"}</span>`, [showNotes])}</button>
        </div>
        <div>
            <ul>
                ${
                    live(
                        () => (showNotes.get() ? todoList.get() : []).map(note => html`<li>${note}</li>`),
                        [todoList, showNotes]
                    )
                }
            </ul>
        </div>
    </div>
    `;
}

document.body.append(app());

live.js's People

Contributors

hadaward avatar

Watchers

 avatar

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.