Socket
Book a DemoInstallSign in
Socket

@rematch/subscriptions

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rematch/subscriptions

Rematch plugin for subscriptions

latest
Source
npmnpm
Version
0.2.2
Version published
Maintainers
2
Created
Source

Rematch Subscriptions

Subscriptions plugin for Rematch.

Install

npm install @rematch/subscriptions

Setup

import subscriptionsPlugin from '@rematch/subscriptions'
import { init } from '@rematch/core'

const subscriptions = subscriptionsPlugin()

init({
  plugins: [subscriptions]
})

Subscriptions

subscriptions: { [string]: (action, state, unsubscribe) => any }

Subscriptions are way for models to listen to changes in the app.

{
  name: 'settings',
  state: {},
  reducers: {
    set: (payload) => payload
  },
  subscriptions: {
    'profile/load': (action, state, unsubscribe) => {
      dispatch.settings.set(action.payload)
    }
  }
}

In this case, subscriptions avoid the need of coupling the auth model to the profile model. Profile simply listens to an action.

Subscriptions help you make isolated models that know nothing about their neighbours.

Use unsubscribe if you'd like an action to fire only once.

{
  name: 'settings',
  state: {},
  reducers: {
    set: (payload) => payload
  },
  subscriptions: {
    'profile/load': (action, state, unsubscribe) => {
      dispatch.settings.set(action.payload)
      unsubscribe()
    }
  }
}

Subscriptions can also use pattern matching. Bear in mind, that the pattern should avoid matching any actions within your model to prevent an infinite loop.

{
  subscriptions: {
    'routeChange/*': (action) => console.log(action)
  }
}

The following patterns are all valid:

modelName/actionName
*/actionName
modelName/*
a-*/b
a/b-*

If possible, pattern matching should be avoided as it can effect performance.

Keywords

@rematch

FAQs

Package last updated on 11 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts