npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ui-component-eventbus-js

v2.3.1

Published

Offers state management and event bus for UI components. Use to create single page applications or add reactive components to projects.

Downloads

26

Readme

RCE Framework

Table of Contents

  1. Documentation
  2. Examples
  3. Getting Started
  4. Creating a Component
  5. Registering a Component
  6. Emitting and Listening to Events

Introduction

RCE (Root Components and Event-bus) emphasizes getting back to the roots of component-based development. RCE's component builder is a lightweight, event-driven JavaScript framework for building highly interactive and modular web applications. By leveraging an event bus system, RCE facilitates communication between components without requiring them to be directly aware of each other, enabling a decoupled and maintainable architecture.

Features

  • Event-Driven Architecture: Components communicate through a centralized event bus, promoting loose coupling and enhanced modularity.
  • Component Lifecycle Hooks: Utilize hooks like beforeCreate, onMount, and afterUpdate for fine-grained control over the component lifecycle.
  • State Management: Manage component states with ease, allowing for reactive updates and efficient rendering.
  • Template Rendering: Define and manipulate component templates, supporting both inline and external templates for dynamic content rendering.
  • No compiler or build process: The original framework is written in vanilla JavaScript and is readily extensible at less than 1500 lines of code.

Limitations

  • Developer Experience: Requires proficiency in vanilla JavaScript and relies on a strong understanding of fundamental patterns with a large focus on being intentional.
  • Verbosity: This is not a declarative system; you will be writing a lot of code with explicit system instructions. There isn't a templating language or special utility classes that serve multiple purposes. (Maybe one day we'll make it more class based at best).
  • Process Orientation: An opinionated system focusing on impact, business value, and explicit workflows. Common actions make it easier to estimate production, and generate documentation for component libraries and process diagrams. For example: no build process means minor changes won't cost the organization countless hours of production.
  • Type Handling: Use of JsDocs is highly encouraged.

Getting Started

Installation

You can include the RCE framework in your project by adding the Factory.js file to your HTML file or importing it into your JavaScript module.

<script type="module">

    // Build configuration driven components
    import { Factory, ComponentConfigs, ComponentProps } from '/rce/Factory.js';

    // Trigger signals in components. Subscribers will receive signals and can react
    import { EventBus, GlobalComponentEvents } from '/rce/EventBus.js';  

</script>

Creating a Component

Define a component configuration object's state, properties, and lifecycle hooks. (Only configure what you need; omit the rest from your configuration.)

ComponentConfigs.myComponentConfig = {
    eventBus: [ 'GlobalComponentEvents' ],
    state: {
        componentName: 'MyComponent',
        myKey: 'My value'
        /* Additional state properties... */
    },
    props: { /* Store commonly reused schema and eventlisteners */ }
    hooks: {
        beforeCreate : function( state ) { },
        beforeUpdate : function( delta ) { }, 
        onUpdate     : function( delta ) { },
        afterUpdate  : function( delta ) { }, 
        afterCreate  : function( state ) { },
        beforeMount  : function( state ) { }, 
        onMount      : function( state ) { },                
        afterMount   : function( state ) { }
    },
    get: { /* Get values from state */ },
    commit: { /* Commit changes to state */ },
    dispatch: { /* Dispatch actions to generate or respond to state change */ },
    template : `
        <div>
            <h1 id="textHere"></h1>
            <form>
                <input id="someInput" type="text"/>
            </form>
        </div>
    `, 
    debug: true, /* Default value false */
};

Registering a Component

Register your component with the RCE framework to bring it to life.

The RCE Factory module decorates and stores a new Javascript object (not a class) in the Factory.ComponentStore. The module can be referenced or retrieved by using the Factoriy.getComponentByName() method.

Factory.registerComponent( Component.myComponentConfig );

Emitting and Listening to Events

Components can listen to events from the event bus and emit events to communicate with other components.

/**
 * Step 1 - Subscribe to an event bus
 */

ComponentConfigs.componentOne.eventBus[] = 'MyBus';
ComponentConfigs.componentTwo.eventBus = ['MyBus', 'AnotherBus'];

/**
 * Step 2 - 
 * 
 * Commit new values within a dispatched action. This triggers 
 * a signal that is caught by the event bus and distributed to 
 * modules subscribed to that bus. 
 * 
 * Note: The signal is only published if there is a delta between 
 *       componentOne's previous state and future state
 */

componentOne.dispatch.SomeAction = function ( newInput ) {
    // Do something with the newInput ...

    // ... Save the input
    this.component().commit.state({
        myKey: processedInput
    });
} 

/**
 * Step 3 - React to the signal in another component
 */

componentTwo.dispatch.update = function ( componentKey, delta ) {
    console.log( delta.myKey );
}

Further Documentation

For detailed documentation on component configuration, lifecycle hooks, state management, and event handling, refer to the RCE Documentation.

  1. Component Configuration
  2. Component Life Cycle
  3. Event Bus - Subscription Model
  4. Event Bus - Notifications

Examples

Check out the examples directory for sample applications and use cases to get started with RCE.

  1. Server-side Rendering Example
  2. Client-side Rendering Example

License Component Builder is GNU GENERAL PUBLIC LICENSE licensed.