Giter Club home page Giter Club logo

homegrown's Introduction

homegrown

A stupidly simple frontend framework with ssr support

(I did write better documentation but I lost it somehow...)

Setup

Install node module:

npm install homegrownjs

To setup the backend with ssr, I would reccomend using the go backend which has all the processing setup. Use the code in the main.go file in the example project: homegrown-homepage. It would proably be easier to clone the project and then edit the files in the pages/root to follow along with the simple tutorial.

Tutorial

Each component is simply a function that returns an html component:

export function TestComponent(props: hg.Props, ctx hg.Ctx) {
    return `
        here be dragons
    `

}

Use Props

Simply access the props map as you would for any other js map:

export async function TestComponent(props: hg.Props, ctx: hg.Ctx) {
    return `
        here be dragons and ${props.get("propName")}
    `
}

Hydrate promises on resolve

To hydrate the piece of the page once the promise has resolved we use the hg.hydr function:

function sleep(time: number) {
    return new Promise<null>((resolve, reject)=>{setTimeout(()=>{resolve(null)}, time)})
}

var fetchPost = async () => {
        await sleep(5000) // simulate doing some processing
        return fetch("https://jsonplaceholder.typicode.com/posts/1").then((val: Response) => val.text())
    }


export async function TestComponent(props: hg.Props, ctx: hg.Ctx) {
    return `
        here be dragons and ${props.get("name")}
        ${await hg.hydr(
            "This is from the server. Hello!",
            fetchPost(), "componentNameGoesHere", ctx
        )}
    `
}

homegrown's People

Contributors

jangordon 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.