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

extensioner

v1.18.4

Published

Extensioner is responsible for managing apps modules. Scalable apps become easy

Downloads

15

Readme

EXTENSIONER

Build Status Downloads Downloads NPM version

DESCRIPTION

Usually applications should be split into smaller logical parts called modules. A problem appears when each module should be configured in multiple places. And when there is lot of different modules, configuring each of them separately became a challenge.

This library is responsible for managing all app modules. You only initialize everything once and then just register and unregister new and old modules.

EXAMPLE

In each module lets create init file

someCustomModuleA init file:

//modules/someCustomModuleA/index.js

export default {
    properties: {
        customPropertyA: "customValueAA",
        customPropertyB: "customValueAB"
    },
    events: {
        customEventA: () => "customResponseFromEventAA",
        customEventB: () => "customResponseFromEventAB"
    }
}

As you can see this is just an object with properties : properties and events

someCustomModuleB init file:

//modules/someCustomModuleB/index.js

import { Extension } from "extensioner";
export default class SomeCustomModuleB extends Extension{
    constructor(someInitOptions) {
        super();
        this.setProperty("customPropertyA", "customValueBA");
        this.setProperty("customPropertyC", "customValueBC");
        this.onCustomEventA = this.onCustomEventA.bind(this);
        this.setEventListener("customEventA", this.onCustomEventA);
        this.onCustomEventC = this.onCustomEventC.bind(this);
        this.setEventListener("customEventC", this.onCustomEventC);
    }
    onCustomEventA (initValue) {
        return "customResponseFromEventBA";
    }
    onCustomEventC (initValue) {
        return "customResponseFromEventBC";
    
    }
}

In above init file we created class which extends from Extension.

someCustomModuleC init file:

//modules/someCustomModuleC/index.js

export default function someCustomModuleC(someInitOptions) {
    return {
        properties: {
            customPropertyB: "customValueBC",
            customPropertyC: "customValueCC"
        },
        events: {
            customEventB: () => "customResponseFromEventCB",
            customEventC: () => "customResponseFromEventCC"
        }
    }
}

In above init file we created function which will return extension object

Lets create manager instance and register modules

//index.js

import { Manager } from "extensioner";
import someCustomModuleA from "./modules/someCustomModuleA/index.js";
import SomeCustomModuleB from "./modules/someCustomModuleB/index.js";
import someCustomModuleC from "./modules/someCustomModuleC/index.js";

const manager = new Manager();
manager
    .registerExtension("someCustomModuleNameA", someCustomModuleA)
    .registerExtension("someCustomModuleNameB", new SomeCustomModuleB())
    .registerExtension("someCustomModuleNameC", someCustomModuleC());

Lets prepare event and call it.

const event = manager.createEvent("customEventA");

const responses = event();
/**
*   responses is equal:
*   [
*       "customResponseFromEventAA",
*       "customResponseFromEventBA"
*   ]
*/

Lets prepare event with async event resolver

import { asyncListCompose } from "extensioner";
const event = manager.createEvent("customEventB", asyncListCompose);

event()
    .then(responses => {
        /**
        *   responses is equal:
        *   [
        *       "customResponseFromEventAB",
        *       "customResponseFromEventCB"
        *   ]
        */
    });

Lets get property values from all modules

manager.getExtensionsWithProperty("customPropertyA").forEach(extension => {
    extension.getProperty("customPropertyA")
})

API

Manager component

new Manager(): manager

Creates new manager

new Extension(): extension

Each module should have one root class with all settings and this class should extend Extension

manager.registerExtension(extensionInstanceName: String, extension: Extension): manager

Allow to register/add any new extension and return same manager instance. Second argument can be instance of Extension class

OR

manager.registerExtension(extensionInstanceName: String, extension: Object): manager

Allow to register/add any new extension and return same manager instance. Second argument is simple object with properties: properties and events

manager.getExtensionJoints([onlyActive = true]): Array

When onlyActive flag is true it will return all active extensions joints for previously registered extensions When flag is false then it will return all extensions.

manager.getExtensionJointsWithProperty(propertyName: String [, onlyActive = true]): Array

When onlyActive flag is true it will return array of active extension joints with specific property When flag is false then it will return all extensions with specific property

manager.getExtensionJointsWithEventListener(eventName: String) [, onlyActive = true]): Array

When onlyActive flag is true it will return array of active extension joints with specific event listener When flag is false then it will return all extensions with specific event listener

manager.isExtensionJointEnabled(extensionInstanceName: String): Boolean

Return true if extension with ext ensionInstanceName exist and is active. Otherwise false

manager.hasExtensionJoint(extensionInstanceName: String): Boolean

Returns true if extension with extensionInstanceName exists.

manager.disableExtensionJoint(extensionInstanceName: String): Boolean

Disable extension with undefinedextensionInstanceName name then it will return true. If extension doesn't exist it will return false

manager.enableExtensionJoint(extensionInstanceName: String): Boolean

Enable extension with extensionInstanceName name then it will return true. If extension doesn't exist it will return false

manager.getExtensionJoint(extensionInstanceName: String): ExtensionJoint

Return extension joint by its name or null if doesn't exist.

manager.getPropertyValues(propertyName: String [, onlyActive = true]): Object

Return object where keys are extension joints names, and values are extensions properties values

manager.createEvent(eventName: String [, composeFunction: Function]): Function

Create event function. Next step is to call this function to trigger event. Response from compose function

const event = manager.createEvent("onRenderHeader", (extensions, eventName, value) => { extensions.map(extension => extension.getEventListener(eventName)(value)) });
event()
    .then(response => {
        //do something with responses
    })

Compose functions

composeFunction is function which compose responses from corresponding event handler.

function composeFunction(extensions: <Extension>Array, eventName: String, value: any): any

This function will get :

  • extensions - list of extensions which listening for event
  • eventName - event name which is resolving
  • value - init value from called event

By default is used syncListCompose function which will call sync all event handlers, returns response which will be fulfilled with array of responses.

Available functions :

  • syncListCompose - will call all event handlers synchronously and return list of responses
  • syncMapCompose - will call all event handlers synchronously and return object where keys are extensions names and values are responses
  • asyncListCompose - will call all event handlers asynchronously and return promise which will resolve to array of responses
  • asyncMapCompose - will call all event handlers asynchronously and return promise which will resolve to object where keys are extensions names and values are responses

ExtensionJoint component

This is object containing reference to Manager and to Extension, It also have name. It is created only in manager when extension is registered

extensionJoint.isEnabled(): Boolean

Return true when extension is enabled

extensionJoint.enable(): void

Enable extension

extensionJoint.disable(): void

Disable extension

extensionJoint.getExtension(): Extension

Returns extension

extensionJoint.getName(): String

Returns extension name

extensionJoint.getManager(): Manager

Returns manager

Extension component

new Extension([extensionData: Object]): extension

Create new extension. ExtensionData is simple object with properties: properties and events.

extension.setProperty(propertyName: String, value: any): extension

Add new property to module

extension.hasProperty(propertyName: String): boolean

Check if module has property.

extension.getProperty(propertyName: String): any

Return property value.

extension.setEventListener(eventName: String, handler: Function): extension

Add new event listener

extension.hasEventListener(eventName: String): boolean

Check if module has event Listener.

extension.getEventListener(eventName: String): Function

Return event handler.

LICENSE

MIT