0.7.0 • Published 17 days ago

microrender v0.7.0

Weekly downloads
-
License
LGPL-3.0-or-later
Repository
gitlab
Last release
17 days 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.

SyntaxImplemented?Description
$.form(field: string) => string | voidGet form fields from POST requests. undefined unless the method is POST.
$.fetch(url: any, ?options: RequestInit) => Promise<Response>Wrapper around the fetch api. Uses cloudflare service bindings where possible.
$.url() => URLGets the current URL. Can be modified in the control hook.
$.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 "".

Render APIs

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

SyntaxImplemented?Description
$(selector: string, callback: (elmt: Element) => void) => voidJQuery-like selector API. Runs callback for each matching element.
Element.getAttribute(attr) => string | voidSimilar to DOM Element.getAttribute()
Element.hasAttribute(attr) => booleanSimilar to DOM Element.hasAttribute()
Element.setAttribute(attr) => voidSimilar to DOM Element.setAttribute()
Element.removeAttribute(attr) => voidSimilar to DOM Element.removeAttribute()
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.getStyle(property: string) => string | voidGet a CSS property in the inline style tag.
Element.setStyle(property: string, value: string) => voidSet a CSS property in the inline style tag. A blank string removes it.
Element.removeStyle(property: string) => voidRemove a CSS property in the inline style tag.
Element.style(property: string, ?value: string) => string | voidShorthand for (get/set)Style(). Similar to JQuery .css() but uses inline styles.
Element.getClass($class: string) => booleanSimilar to DOM Element.classList.contains()
Element.setClass($class: string, value: boolean) => voidSimilar to DOM Element.classList.add() and Element.classList.remove()
Element.toggleClass($class: string) => voidSimilar to DOM Element.classList.toggle()
Element.class($class: string, ?value: bool) => booleanShorthand for (get/set)Class()
Element.value(?value: string) => stringModify/read the value attribute/property of an element.
$.data(attr: string) => string | voidGet data-* attributes from the fragment 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.

SyntaxImplemented?Description
$.url(url: string \| URL) => voidChanges the current URL.
$.error(code: number) => voidChanges the current HTTP status.
$.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) => 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.

SyntaxImplemented?Description
HTML <microrender-fragment name="">Embed another fragment within this fragment.
HTML name="microrender:js"Add the browser JS to the page.
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.7.0

17 days ago

0.6.3

22 days ago

0.6.5

22 days ago

0.6.4

22 days ago

0.6.2

29 days ago

0.6.1

1 month ago

0.6.0

1 month ago

0.5.0

1 month ago

0.4.1

1 month ago

0.4.2

1 month ago

0.4.0

1 month ago

0.3.0

1 month ago

0.2.0

1 month ago

0.1.0

2 months ago

0.0.0

2 months ago