Observer
An asynchronous observer that batches updates per subject and callback.
import { Observer } from "@schukai/monster/source/types/observer.mjs";Observer is the asynchronous callback primitive behind Monster's observable structures. It batches updates per subject inside one microtask cycle so duplicate triggers collapse into one execution.
Use it when update notifications should stay cheap and consistent even if a subject changes several times in quick succession.
/** this example does not use an extra script **/
Monster
Build fantastic websites!
Efficient Web Design with Custom Components
Monster is the foundation of our front-end projects and greatly simplifies the creation of websites and applications. Our library includes a wide range of pre-built, elegant and customizable components. From precise buttons that provide feedback on user actions to complex data lists with sorting and filtering capabilities, Monster gives you the tools you need to design quickly and consistently.
As an open-source project, Monster is constantly being expanded and refined by a dedicated team. Our goal is to constantly improve the functionality and at the same time make it intuitive to use to make your everyday work easier.
<monster-button id="my-button">
Click Me!
</monster-button>
const myButton = document.getElementById('my-button');
myButton.setOption("actions.click", () => {
myButton.setState("successful", 2000);
})
Below, you'll find the "Click Me!" button. When clicked, a checkmark briefly appears to confirm the operation was successful.
The accompanying source code, shown on the right, uses HTML to define the button and JavaScript to set its state to "successful" for 2000 milliseconds following the click.
This demonstrates a straightforward way to provide immediate feedback on user interfaces.
Web Components for Tomorrow's Needs
Customizable Components
Monster offers a diverse suite of web components that blend seamlessly into any design. Customize colors, shapes, and functionalities to fit your specific needs.
Optimized for consistent performance across all screen sizes, our components ensure a smooth user experience on every device.
Efficient Integration & Maintenance
With Monster's modular structure, you can swiftly add or remove components without overhauling your entire codebase.
This feature streamlines project maintenance and expedites the deployment of new features, enhancing overall productivity.
Future-Proof Technology
Committed to innovation, we continuously update Monster to align with the latest web standards and browser technologies.
This proactive approach ensures that your projects remain compatible and secure against future technological shifts.
The current width of the area is too small to display the content correctly.
Schedule A Deduplicated Observer Update
import { Observer } from "@schukai/monster/source/types/observer.mjs";
const output = document.getElementById("observer-output");
let runs = 0;
const observer = new Observer(function () {
runs += 1;
output.textContent = `runs: ${runs}`;
});
document.getElementById("observer-run").addEventListener("click", async () => {
runs = 0;
output.textContent = "scheduled";
const subject = { name: "demo" };
await Promise.all([observer.update(subject), observer.update(subject)]);
});Exported
ObserverDerived from
BaseOptions
The Options listed in this section are defined directly within the class. This class is derived from several parent classes. Therefore, it inherits Options from these parent classes. If you cannot find a specific Options in this list, we recommend consulting the documentation of the Base.
Properties
The Properties listed in this section are defined directly within the class. This class is derived from several parent classes. Therefore, it inherits Properties from these parent classes. If you cannot find a specific Properties in this list, we recommend consulting the documentation of the Base.
Methods
The methods listed in this section are defined directly within the class. This class is derived from several parent classes. Therefore, it inherits methods from these parent classes. If you cannot find a specific method in this list, we recommend consulting the documentation of the Base.
Constructor
constructor(callback,args)callback{function}: The function to execute on update.args{...*}: Additional arguments to pass to the callback.
Behavioral methods
addTag(tag)tag{string}: tag
removeTag(tag)tag{string}: tag
update(subject)subject{object}: The subject object that triggered the update.
State query methods
hasTag(tag)tag{string}: tag
Structural methods
getTags()Static methods
[instanceSymbol]()2.1.0instanceof operator.Other methods
arguments()callback()Events
This component does not fire any public events. It may fire events that are inherited from its parent classes.