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

redux-favicon

v0.1.4

Published

Dynamic favicon middleware for Redux.

Downloads

218

Readme

Redux Favicon

build status npm version Coverage Status

Redux middleware that lets you display notification badges in the favicon:

Uses Favico.js under the hood, exposing its customization when needed but allowing you to display notification badges as easily as:

// app.actions.js

export function newMessage() {
  return {
    type: 'NEW_MESSAGE',
    meta: { favicon: 'increment' }
  }
}

Installation

Preferred: NPM

npm i -S redux-favicon

Also available: UMD

UMD builds are also available, for single-file usage or quick hacking in a JSbin. Simply add dist/redux-favicon.js or dist/redux-favicon.min.js to your file in a <script> tag. The middleware will be available under ReduxSounds.

Setup

Import the module into your configure-store file, pre-load it with settings, and apply it to the store:

/* configure-store.js */

import { createStore, combineReducers, applyMiddleware } from 'redux';
import faviconMiddleware from 'redux-favicon';

import reducer from '../reducers';

// Redux Favicon accepts a configuration object. The options are explained below.
const faviconConfig = {
  animation:  'slide',
  position:   'up',
  type:       'rectangle',
  bgColor:    '#123456',
  textColor:  '#314159'
};

// Pre-load our middleware with our config.
const loadedFaviconMiddleware = faviconMiddleware(faviconConfig);

// Use as you would any other middleware.
const store = createStore(reducer, applyMiddleware(loadedFaviconMiddleware));
// (Using the condensed createStore released in Redux v3.1.0)

The config file is optional, but you do need to invoke the favicon middleware either way.

Options

Redux Favicon uses Favico.js v0.3.10 under the hood. Favico.js offers some additional bells and whistles that are untested with this middleware, but the following options are supported:

| Attribute | Default | Details | |------------|------------|----------------------------------------------------------------------------------------------------------| | bgColor | #d00 | Badge background color | | textColor | #fff | Badge text color | | fontFamily | sans-serif | Text font family (Arial, Verdana, Times New Roman, serif, sans-serif,...) | | fontStyle | bold | Font style (normal, italic, oblique, bold, bolder, lighter, 100, 200, 300, 400, 500, 600, 700, 800, 900) | | type | circle | Badge shape (circle, rectangle) | | position | down | Badge position (up, down, left, upleft) | | animation | slide | Badge animation type (slide, fade, pop, popFade, none ) |

Usage

Once your store is created, dispatching actions that trigger sounds is simple.

Using the convention established in the rafScheduler Middleware example, a new meta property can be attached to actions.

By attaching a favicon property to the meta object, you can specify the new number you'd like to display. Several convenience strings are offered as well.

Examples:

// Set a new badge number.
// Accepts any integer.
// Sending 0 or a negative number hides the badge.
{
  type: UPDATE_SCORE,
  meta: {
    favicon: 12
  }
}

// Increase the current favicon number by 1.
// If there is no favicon badge currently displayed, it will be set to `1`
{
  type: RECEIVE_MESSAGE,
  meta: {
    favicon: 'increment'
  }
}

// Decrease the current favicon number by 1.
// If the current value is 1 or lower, this action removes the badge.
{
  type: RECEIVE_MESSAGE,
  meta: {
    favicon: 'decrement'
  }
}

// Remove the badge
// This is equivalent to sending a value of `0`
{
  type: RECEIVE_MESSAGE,
  meta: {
    favicon: 'reset'
  }
}

Troubleshooting

I've done my best to make common errors communicated and explained via the console. Here are some of the errors you might encounter:

redux-favicon middleware not preloaded!
You need to first call reduxFavicon with its configuration to initialize it, THEN pass it to createStore.

When passing the middleware to the store, be sure to invoke it first:

// Note that faviconMiddleware is being invoked:
const store = createStore(reducer, applyMiddleware( faviconMiddleware() ));
//                                                                   ^^

Warning: Favico not affected.
You provided a floating-point value: _____.
You need to provide an integer, or a keyword value.

This error is shown when the value dispatched to redux-favicon is a non-integer value. Decimals cannot be displayed in the favicon badge, only whole numbers.


Warning: Favico not affected.
You provided a string value: ______.
The only strings we accept are: 'increment', 'decrement', 'reset'.

This one is pretty self-explanatory. String values are generally disallowed, with the exception of a few handy shortcuts for specifying relative adjustments or resets.


Warning: Favico provided an illegal type.
You provided a a value of type: ______.
We only accept integers or strings.

Also pretty self-explanatory, redux-favicon does not like when you give it an array, object, function, etc.


Tests

To run: npm run test

Using Mocha for test-running, Chai Expect for assertions, and Istanbul for test coverage.

Planned functionality

I don't have much planned, beyond maintenance. I could wrap additional Favico features (like dynamically specifying an image for a favicon, or using the user's webcam), but these aren't features that I personally have a need for.

Do get in touch if you have ideas for ways to improve this project :)

Contributions

Contributors welcome! Please discuss additional features with me before implementing them, and please supply tests along with any bug fixes.

License

MIT