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

@uncover/ward

v0.2.26

Published

Ward micro frontends frameworks

Downloads

52

Readme

ward

npm version Last Push

Ward is a small JavaScript library providing tools to ease microfrontend development regardless of the chosen frameworks.

Concept

Ward provides seamless communication between existing frames by sending standardized messages coupled with dynamic plugin discovery mecanism.

API

Ward

| Function | Arguments | Description | | ---------- | ------------ | ----------- | | Features | | addService | id?: string | Creates a new service that will listen to incoming messages. | | loadPlugin | url?: string | ... | | reset | | Drop all services and plugins (should not be called). | | Inspection | | register | | ... | | unregister | | ... | | notify | | ... |

Service

Service objects are the basic communication entities in Ward. You can instanciate as many Service objects as needed in any layer of your application.

Service objects provide the ability to send a message that will be received by all other existing services in your execution environment, including the ones created in sub frames or parent frame.

| Function | Arguments | Description | | ------------- | --------- | ----------- | | addHandler | fn: (message: { type: string, payload: any }) => void | Add a handler to be called each time a message is received. | | removeHandler | fn: (message: { type: string, payload: any }) => void | Removes a previously added handler. | | sendMessage | message: { type: string, payload: any } | Sends a message to all other services. | | onMessage | message: { type: string, payload: any } | Sends a message to this service. | | terminate | _ | Prevent the service from receiving any further messages (can not be recycled) |

Usage

Installation

npm add @uncover/ward

Using Message Services

Example

Example #1: handlers

The following example creates a service that will log all messages sent to the Ward event bus.

import Ward from '@uncover/ward'

function messageLog(message) {
  console.log(`received message ${message.type}:`)
  console.log(JSON.stringify(message.payload))
}

// Create the service (with optionnal id)
const service = Ward.addService('my-service')

// Add a handler (will be called for each received message)
service.addHandler(messageLog)

// Remove a handler (stop calling it on message received)
service.removeHandler(messageLog)

// Terminate the service (stops receiving messages, service should be dropped)
service.terminate()
Example #2: sending messages

The following example creates a service and sends a message to the Ward event bus. The message will be dispatched to all other existing services.

import Ward from '@uncover/ward'

// Create the service (with optionnal id)
const service = Ward.addService('my-service')

// Send a message that will be received by all other services
service.sendMesage({
  type: 'my-message-type',
  payload: {
    data: 'myData',
    otherData: 'otherData'
  }
})

// Terminate the service (stops receiving messages, service should be dropped)
service.terminate()
Example #3: sending messages to handlers

Allthough considered a bad pattern, in some scenarios you might want to send a message to the handlers of your service. You can do it by simulating a message reception by the service.

import Ward from '@uncover/ward'

// Create the service (with optionnal id)
const service = Ward.addService('my-service')

// Send a message that will be received by all handlers of this service
service.onMesage({
  type: 'my-message-type',
  payload: {
    data: 'myData',
    otherData: 'otherData'
  }
})

// Terminate the service (stops receiving messages, service should be dropped)
service.terminate()