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

frint-component-utils

v5.7.2

Published

Component utils package for Frint

Downloads

419

Readme

frint-component-utils

npm

Component utils package of Frint


Guide

This package is aimed at enabling other reactive rendering/templating libraries integrate with FrintJS, and not to be used directly by developers in their applications.

For example, take a look at frint-react for its implementation using this package internally.

Installation

With npm:

$ npm install --save frint-component-utils

Handlers

Handlers concept follows a spec for the lifecycle of a reactive component, without tying itself to any specific library (like React or Vue). They are basically just objects with functions, which will be exposed as methods when composed together into a single instance.

This enables other libraries to integrate with FrintJS as easily as possible. The monorepo here will always provide the handlers logic for maintaining the same behaviour, while others can start implementing these handlers with their preferred rendering library (Vue or Preact for example).

Within the monorepo, we will be consuming these handlers ourselves too to create React-specific packages.

Handler spec

This is the default handler interface which other handlers are expected to implement as needed:

{
  // options
  app: null,
  component: null,

  // lifecycle: creation
  initialize() {},
  beforeDestroy() {},

  // data
  getInitialData() {},
  setData(key, value) {},
  setDataWithCallback(key, value, cb) {},
  getData(key) {},

  // props
  getProp(key) {},
  getProps() {},

  // lifecycle: mounting
  beforeMount() {},
  afterMount() {},

  // lifecycle: re-rendering
  beforeUpdate() {},
  shouldUpdate(nextProps, nextData) {},
  afterUpdate() {},

  // other
  getMountableComponent(app) {}
}

Handler implementation

For example, frint-react has an implementation of the handler targeting React. And it was done as follows:

{
  setData(key, value) {
    this.component.setState({
      [key]: value,
    });
  },
  setDataWithCallback(key, value, cb) {
    this.component.setState({
      [key]: value,
    }, cb);
  },
  getData(key) {
    return this.component.state[key];
  },
  getProps() {
    return this.component.props;
  },
  getProp(key) {
    return this.component.props[key];
  }
}

You can also see how multiple handlers are composed together and implemented in Region and observe Components in frint-component-handlers and frint-react packages.

API

DefaultHandler

DefaultHandler

The interface of a default handler object, that other handlers are expected to override.

composeHandlers

composeHandlers(...handlers)

Arguments

  1. handler (Object): with functions to override from default/previous handlers.

Returns

Handler: Instance of handler after composing with all handlers.

streamProps

streamProps(defaultProps = {})

Helper function, for composing your props inside observe, and then generating and returning an single Observable.

Arguments

  1. defaultProps (Object [optional]): Default props to start with.

Returns

Streamer instance that implements these methods below:

All set* methods return the same Streamer instance so multiple set calls can be chained in one go.

set

set(key, value)

set(plainObject)

set(observable$, ...mapperFunctions)

setKey

setKey('key', 'value')

setPlainObject

setPlainObject({ key: 'value' })

setObservable

setObservable(observable$, ...mapperFunctions)

You can set as many mapper functions until you reach a value of your needs.

setObservable(
  observable$,
  props => props, // no modification
  propsAgain => modifiedProps // with modification
)

setDispatch

setDispatch(actionCreators, store)

setDispatch({
  incrementCounter: incrementCounter,
  decrementCounter: decrementCounter,
}, store)

get$

get$()

Returns an Observable.