All Projects → joshwcomeau → Redux Favicon

joshwcomeau / Redux Favicon

Licence: mit
Redux middleware that displays colourful notification badges in the favicon area.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Redux Favicon

Serve Favicon
favicon serving middleware
Stars: ✭ 586 (+468.93%)
Mutual labels:  middleware, favicon
Twig
Twig - less is more's web server for golang
Stars: ✭ 98 (-4.85%)
Mutual labels:  middleware
Lambcycle
🐑🛵 A declarative lambda middleware with life cycle hooks 🐑🛵
Stars: ✭ 88 (-14.56%)
Mutual labels:  middleware
Connect Cas2
NodeJS implement of CAS(Central Authentication Service) client.
Stars: ✭ 91 (-11.65%)
Mutual labels:  middleware
Backoffice Administration
Stars: ✭ 89 (-13.59%)
Mutual labels:  middleware
Depictr
A middleware for rendering static pages when crawled by search engines
Stars: ✭ 92 (-10.68%)
Mutual labels:  middleware
Middleman
Dead simple PSR-15 / PSR-7 middleware dispatcher
Stars: ✭ 87 (-15.53%)
Mutual labels:  middleware
Rexlin600.github.io
系列博客、涵盖领域广、不定时更新、欢迎加入
Stars: ✭ 102 (-0.97%)
Mutual labels:  middleware
Rye
A tiny http middleware for Golang with added handlers for common needs.
Stars: ✭ 95 (-7.77%)
Mutual labels:  middleware
Chi
lightweight, idiomatic and composable router for building Go HTTP services
Stars: ✭ 10,581 (+10172.82%)
Mutual labels:  middleware
Laravel Analytics
Analytics for the Laravel framework.
Stars: ✭ 91 (-11.65%)
Mutual labels:  middleware
Guzzle retry middleware
Middleware for Guzzle v6+ that automatically retries HTTP requests on 429, 503 responses.
Stars: ✭ 90 (-12.62%)
Mutual labels:  middleware
Laravel Localize Middleware
Configurable localization middleware for your Laravel >=5.1 application
Stars: ✭ 92 (-10.68%)
Mutual labels:  middleware
Service Tools
Prepare your Node.js application for production
Stars: ✭ 89 (-13.59%)
Mutual labels:  middleware
Dotweb
Simple and easy go web micro framework
Stars: ✭ 1,354 (+1214.56%)
Mutual labels:  middleware
Botbuilder Community Js
Part of the Bot Builder Community Project. Repository for extensions for the Bot Builder JavaScript SDK, including middleware, dialogs, recognizers and more.
Stars: ✭ 88 (-14.56%)
Mutual labels:  middleware
Corser
CORS middleware for Node.js
Stars: ✭ 90 (-12.62%)
Mutual labels:  middleware
Tower
async fn(Request) -> Result<Response, Error>
Stars: ✭ 1,305 (+1166.99%)
Mutual labels:  middleware
Rxcache
A local reactive cache for Java and Android. Now, it supports heap memory、off-heap memory and disk cache.
Stars: ✭ 102 (-0.97%)
Mutual labels:  middleware
Redux Search
Redux bindings for client-side search
Stars: ✭ 1,377 (+1236.89%)
Mutual labels:  middleware

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].