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

terrific-singleton

v1.0.0

Published

helper module to use terrific in react projects

Downloads

38

Readme

Terrific Singleton

Terrific singleton is a small wrapper for terrific.
Features:

  • Fixed memory leaks of stop method
  • Allows to use ES6 classes for module creation
  • Utils for easier react/angular integration

Supports classic terrific usage

If you don't need intellisense and other advantages of ES6 classes you can still use the old object annoation

import { createModule } from 'terrific-singleton'

createModule('DatePicker', {
  start(resolve) {
    resolve()
  }
})

ES6 classes

With ES6 classes you get better intellisense and other advantages of ES6 classes and typings.

import { createModule } from 'terrific-singleton'
import { TerrificSpec } from 'terrific-singleton/terrific-module'

export default class DatePicker extends TerrificSpec {
  start(resolve) {
    resolve()
  }
} 
createModule('DatePicker', DatePicker)

Typings for modules

This package provides typings for your classes

import { createModule } from 'terrific-singleton'
import { TerrificSpec } from 'terrific-singleton/terrific-module'

export default class DatePicker extends TerrificSpec {
  start(resolve) {
    resolve()
  }
} 
createModule('DatePicker', DatePicker)

Decorators

Instead of calling create module after the class you can also use createModule as a decorator

import { createModule } from 'terrific-singleton'
import { TerrificSpec } from 'terrific-singleton/terrific-module'

@createModule('DatePicker')
export default class DatePicker extends TerrificSpec {
  start(resolve) {
    resolve()
  }
} 

Utility features

startNode

Allows you to start a specific dom node after the DOM ready event

const demo = document.querySelector('.demo')
startNode(demo).then((moduleInstance) => console.log(moduleInstance, 'was loaded'))

getModuleByDomNode

Returns the terrific module instance to call public methods e.g. from React or Angular

const demo = document.querySelector('.demo')
const mod = getModuleByDomNode(demo)
mod.setValue('bar')

stopNode

Tears down a module

const demo = document.querySelector('.demo')
stopNode(demo)

waitForBootstrap

Returns a promise which will be fullfilled once the initial bootstrap is complete This might be handy if your Angular or React bridge is waiting for the modules to be available for the very first time

waitForBootstrap().then(() => console.log('Initial bootstrap complete.'))

waitForModuleInitialisiation

Same like waitForBootstrap but it will also work for components which boot lazy after the initial bootstrap
This might be handy if you boot components with Angular or React

waitForModuleInitialisiation().then(() => console.log('All modules are initialized'))

bootstrap

Start all terrific components which where registrered and initialize all terrific modules found in the current dom This is a replacemant for the terrific application.registerModules() and application.start() methods.

document.addEventListener('DOMContentLoaded', bootstrap)

createModule

Same api like the original createModule but with additional support for ES6 classes and decorators

Legacy

createModule('DatePicker', {

})

ES6 classes

export default class DatePicker { .. }
createModule('DatePicker', DatePicker)

ES6 classes and decorators

@createModule('DatePicker')
export default class DatePicker extends TerrificSpec {

Unit tests

This module is unit tested with a code coverage of 100%