- this library will be discontinued and moved as per
v3.0.0
; - use virst instead;
@html_first/simple_signal
is a collections of helper classes/functions to:
- create
web app
that are based onsignal
paradigm;
- reactive;
- declarative;
- auto subscribed reactivity;
- true fine grained DOM reflection (that's right, on
v3
there's no catch, it's now truely fine grained);
- create declarative library (using our
Lifecycle
) that are heavily scoped onwindow.document
, use cases likes:
- for backend centric
HATEOAS
paradigm, by assigningattributeName
(on the html response from the server) to be monitored right after the response is connected to the DOM;htmlFirst
approach, by assigningattributeName
coupled with otherattributeName
and orattributeValue
, to control how an element should behave, directly fromhtml
;
npm i @html_first/simple_signal
// @ts-check
import {
...namedExports
} from '@html_first/simple_signal';
- we ends the support for
prebundled
module in the reason of, most of theinsteresting
parts of this library are need to be typehinted, and that's almost impossible in the prebundled environtment - however it's not that hard if you want to bundle it your self, as we have documented our APIs, so
you can import whichever API you want and then expose it in the
window
object
generate side effect for signal
based reactivity such as for:
const letExample = new Let('')
new $(async(first)=>{
const value = test.value;
if(first){
return;
// return early if you want to opt out from handling the effect immediately,
// also by doing this you can make the `$` slightly more performance 1) when dealing with `async await` on hydration,
// such as data fetching;
}
// handle value
})
// 1) and when all of the effects is registered, you can call `letExample.call$` to call for effect in parallel;
// bassically the same with `Let` but use `new Derived`
collections of static methods helper for animation;
static method prefixed with animation
can be used to generate recuring keyframes,
which in turn can be used in the callback to animate stuffs
App
starter helper for module environtment;
the sole purpose is just to auto import the necessary file in your main js file;
component creation helper using class initiation; behaviour:
- it rendered directly to real DOM;
- library like
bootstrap
css
and it'sjs
parts can select yourelements
for it's functionality;- you have to manually scope your style by
// on Component scope
html`<style>
[${thisInstance.attr}]{
...nestedCSSRules
}
</style>
...
`
- also you might need to explicitly use ">"
directChildOf
selector, as when you try to renderchildComponent
- it could also be accidentally selected;
- render method:
- you put returned value of
thisInstance.attr
on an html element, which- it will be rendered as it's
innerHTML
at theonConnected
event, then- it will used
MutationObserver
to look for changes;
CRUD wrapper class;
-
signal
will be updated from returned value ofread
; -
read
will be called after callingthisInstance
.create
/update
/delete_
, that havetrue
refreshSignal
; /** @template V
- instantiate this class to opt in page templating, by saving html template string on a html document page;
// main page
<div ${templateName}="${path};${selector}"></div>
// template document
<div ${targetAttribute}="${selector}"></div>
- how it works:
- the class itself register a
Lifecycle
fortemplateName
, which then upon connected, it will fetch thepath
then selectstargetAttribute
="selector
" as template that then replace main page element with selected element from template;- fetched page will be then be cached, along with any
[targetAttribute]
on that page
allow the usage of search query based router through class instantiation;
- register by putting import this instance on your js
main file
create shortcuts through class instantiation;
- register by putting import this instance on your js
main file
create named storage (localStorage
or sessionStorage
) through class instantiation;
- register by putting import this instance on your js
main file
- this class is extended from
Let
Let
-signal
based reactivity, wich value are derived from reacting toLet<T>.value
effects that are called in theasyncCallback
this class instantiation;
// @ts-check
const letSingle = new Let(1);
const doubleExample = new Derived(async()=>{
const value = letSingle.value; // autoscubscribed to `letSingle` value changes;
return value * 2; // returned value are to be derivedValue
});
-
dataOnly
:
const dataOnlyExample = Derived.dataOnly(asyncCallback);
- this will automatically opt you out from
domReflector
;
- make sure to check
argument
documentation in yourIDE
typehint
;
type helper for documentScope
use this instead of normal eventListener
declaration for:
- creating
autoqueued
listener
; -
autoScope
_
static methods, insideComponent
scope;
// @ts-check
someObject.addEventListener('click', Event_.listener( (event) => {
// code
}))
- assign element to loop through 'List' as data to render child element using class instantiation;
- loped childElement:
- must have
HTMLElement
as first children;- only first children will be used to loop through
List
, all other children will be deleted from the dom beforeonConnected
event of parentElement;
signal
based reactivity;
assigning newValue to Let insance:
const letSingle = new Let(1, ...args);
letSingle.value++; // 2;
letSingle.value = 3 // 3;
dataOnly
:
const dataOnlyExample = Let.dataOnly(args0);
-
methods
:
call$
: manually triggerseffects
subscribed tothisInstance
;remove$
: unubscribethisInstance
from specificeffect
;removeAll$
: unubscribethisInstance
from all of itseffects
;
- helper class to track connected/disconnected/attributeChanged of an element;
- all global
signal
with dom relector that need to be available forparent scope
should be prefixed withg-
;
type helper for lifecycleHandler
& attributeChangedLifecycle
- helper class to create list that satisfy
Array<Record<string, string>>
const listExample = new List([
{key1: "test", ...keys},
{key1: "test3", ...keys},
])
- usefull for
loops
;
lifecycle wrapper to observe whether element is in viewport
type helper for onViewPortHandler
trigger based callback integrated to the internal library queue handler; can be created using class instantiation;
- helper class to create
ShortCut
through class instantiation; - call
thisInstance.ping
to manually trigger action
helper class for registering and postMessage to webWorker
const worker = new WorkerMainThread(options);
worker.postMessage(message);
helper class to define web worker thread;
new WorkerThread({
onMessage: ({ event, postMessage }) => {
const message = undefined;
// code to handle the message
postMessage(message);
},
});
- scoping helper for
signal
based reactifity stored in static Method of class_
; - if you use our
Component
class, use this class static method, instead of their respective class, forautoscoping
,
which then you can use it's
attr
returned value to mark the element
// on Component scope
onConnected(async()=>{
const data = _.let('test');
html`<div ${data.attr}="innerText"></div>`
})