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-electron-enhancer

v1.11.0

Published

Redux store which synchronizes between instances in multiple process

Downloads

29

Readme

redux-electron-enhancer

js-standard-style Build Status Coverage Status Maintainer status

This library is a fork of redux-electron-store with the following changes:

  • Compatibility with redux-saga
  • Removed features:
    • Removed support for renderer-side reducers / 'synchronous' mode of operation
    • Removed pre-dispatch and post-dispatch callbacks
    • Removed 'only sending actions when watched state changes', renderer stores now get all actions, regardless of whether it's in the filter or not
  • Minor changes:
    • Drop dependency on lodash
    • Use const whenever possible
    • Javascript standard style instead of airbnb's eslint preset

This is an internal fork built for a specific purpose — PRs that add features or complexity will be rejected, as I have no time to maintain it.

Installation

npm i redux-electron-enhancer

Usage

Main Process

import {createStore, applyMiddleware, compose} from 'redux'
import {electronEnhancer} from 'redux-electron-enhancer'

// this is required so that injected events (received from renderers via IPC)
// go through the entire middleware stack again (e.g. redux-saga 'take' effects)
const inject = (x) => store.dispatch(x)

const enhancer = compose(
  applyMiddleware(...middleware),
  // electronEnhancer needs to be last in the chain so that it can dispatch
  // all actions to renderers via IPC (e.g. redux-saga 'put' effects)
  electronEnhancer({inject})
)

// Note: passing enhancer as the last argument to createStore requires redux@>=3.1.0
const store = createStore(reducer, initialState, enhancer)

Renderer / Webview Process

In the renderer process, the store will handle the filter property in its parameter. filter is a way of describing exactly what data this renderer process wishes to be notified of. If a filter is provided, all updates which do not change a property which passes the filter will not be forwarded to the current renderer.

const filter = {
  notifications: true,
  settings: true
}

const enhancer = compose(
  applyMiddleware(...middleware),
  electronEnhancer({filter}),
  DevTools.instrument()
)

// Note: passing enhancer as the last argument to createStore requires redux@>=3.1.0
const store = createStore(reducer, initialState, enhancer)
Filters

A filter can be an object, a function, or true.

If the filter is true, the entire variable will pass through the filter.

If the filter is a function, the function will be called with the variable the filter is acting on as a parameter, and the return value of the function must itself be a filter (either an object or true)

If the filter is an object, its keys must be properties of the variable the filter is acting on, and its values are themselves filters which describe the value(s) of that property that will pass through the filter.

Example Problem:

I am creating a Notifications window for Slack's application. For this to work, I need to know the position to display the notifications, the notifications themselves, and the icons for each team to display as a thumbnail. Any other data in my app has no bearing on this window, therefore it would be a waste for this window to have updates for any other data sent to it.

Solution:

// Note: The Lodash library is being used here as _
const filter = {
  notifications: true,
  settings: {
    notifyPosition: true
  },
  teams: (teams) => {
    return _.mapValues(teams, (team) => {
      return {icons: true}
    })
  }
}

More options are documented in the api docs.

License

MIT