0.11.3 • Published 1 year ago

microrender v0.11.3

Weekly downloads
-
License
LGPL-3.0-or-later
Repository
gitlab
Last release
1 year ago

MicroRender

Simple JS rendering engine that runs on the edge and the browser for optimum speed and compatibility.

MicroRender currently has backends for the browser and Cloudflare pages. Support for other backends eg. NodeJS servers or AWS Lambda may be added in the future.

MicroRender is not yet stable or production-ready, but it is coming closer to that point. View the demo (code; web page) for examples.

Global APIs

These APIs can be accessed on the $ object passed to any hook (exported function) of each fragment.

SyntaxDescription
$.fetch(url: any, ?options: RequestInit) => Promise<Response>Wrapper around the fetch api. Uses cloudflare service bindings where possible.
$.form(field: string) => string | nullGet form fields from POST requests. Returns null unless the method is POST.
$.url() => URLGets the current URL. Can be modified (ie. redirect) in the control hook.
$.path() => stringGets the current URL path. Can be modified in the control hook.
$.search(field: string) => string | nullGet query params from requests. Returns null if there are no query params.
$.error() => numberGets the current HTTP status. Can be modified in the control hook. Default 200.
$.cookie(name: string) => stringReads browser cookies.
$.title() => stringGets the title variable. Can be modified in the control hook. Default "".
$.desc() => stringGets the description variable. Can be modified in the control hook. Default "".
$.loc() => LocationGet the user's approximate location from their IP address.
$.relocate() => Promise<Location>Make a server request to update the user's location. Also updates $.tz() and $.lang()
$.tz() => stringGets the user's timezone from their IP address.
$.lang() => ArrayGets the user's preferred languages from their Accept-Language header
$.props(prop: string) => string | undefinedGet props passed in the $.pass() function or as data attributes on the fragment element.

Render APIs

These APIs can be accessed on the $ object passed to the render hook (export function) of each fragment.

SyntaxDescription
$(selector: string, callback: (elmt: Element) => void) => voidJQuery-like selector API. Runs callback for each matching element.
Element.attr(attr: string, ?value: string) => string | voidShorthand for (get/set/remove)Attribute; similer to JQuery .attr().
Element.boolean(attr: string, ?value: string) => boolean | voidSimilar to .attr() but simplifies working with boolean attributes.
Element.html(content: string) => voidEquivalent to DOM Element.innerHTML = content. HTML is not escaped.
Element.text(content: string) => voidEquivalent to DOM Element.textContent = content. HTML is escaped.
Element.style(property: string, ?value: string) => string | voidShorthand for (get/set)Style(). Similar to JQuery .css() but uses inline styles.
Element.class($class: string, ?value: bool) => booleanShorthand for (get/set)Class()
Element.toggleClass($class: string) => voidSimilar to DOM Element.classList.toggle()
Element.value(?value: string) => stringModify/read the value attribute/property of an element.

Control APIs

These APIs can be accessed on the $ object passed to the control hook (export function) of each fragment. They cannot be used in the render hook as they modify HTTP headers on the server so must run before any of the body code. These (mostly) extend the global APIs.

SyntaxDescription
$.url(url: string \| URL) => voidChanges the current URL (ie. redirects).
$.path(path: string \| URL) => voidEquivalent to $.url()
$.error(code: number) => voidChanges the current HTTP status and re-renders the response.
$.cookie(name: string, value: string) => voidSets browser cookies.
$.title(title: string) => voidSets a title variable readable by all fragments. Should be added to the <title> tag.
$.desc(desc: string) => voidSets a description variable readable by all fragments. Should be added a <meta> tag.
$.pass(fragment: string, ?props: Object) => Promise<void>Passes control to the control hook of another fragment.

Additional Fragment APIs

These are HTML and CSS APIs for defining and using fragments.

SyntaxDescription
HTML <microrender-fragment name="">Embed another fragment within this fragment.
HTML name="microrender:js"Add the browser JS to the page.
HTML name="microrender:ol"Create a dynamic list using a <ol> tag.
HTML name="microrender:ul"Create a dynamic list using a <ul> tag.
HTML data-*=""Add parameters to a fragment. These can be accessed in the render hook using $.data.
HTML microrender-timeout=""Refresh the fragment after the timeout. Only calls the control hook.
CSS :states(--requires-fetch) (.state--requires-fetch polyfill)CSS selector for fragments that need to be fetched from the server.
0.11.0

1 year ago

0.10.1

1 year ago

0.11.1

1 year ago

0.11.2

1 year ago

0.11.3

1 year ago

0.10.0

1 year ago

0.9.0

1 year ago

0.8.0

1 year ago

0.7.0

1 year ago

0.6.3

1 year ago

0.6.5

1 year ago

0.6.4

1 year ago

0.6.2

1 year ago

0.6.1

1 year ago

0.6.0

1 year ago

0.5.0

1 year ago

0.4.1

1 year ago

0.4.2

1 year ago

0.4.0

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago

0.0.0

1 year ago