homegrown

package module
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2023 License: MIT Imports: 6 Imported by: 0

README

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
        )}
    `
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildClient

func BuildClient(path string) []byte

func BuildSSR

func BuildSSR(ctx *RenderCtx)

func SSR

func SSR(ctx *RenderCtx, props [][2]string) []byte

Types

type RenderCtx

type RenderCtx struct {
	// context required for building and ssring a single page
	Script string

	V8Ctx *v8go.Context
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL