🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@spon/connect

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@spon/connect

spon

1.0.1
latest
Source
npm
Version published
Weekly downloads
92
19.48%
Maintainers
1
Weekly downloads
 
Created
Source

Rematch/@spon/core integration

Installation

npm install @spon/core @spon/connect --save or yarn add @spon/core @spon/connect --save

Peer Dependency

  • @spon/core ^2.0.2

See @spon/core for documentation

You’ll need to know how to use rematch to use this feature. Spon.js exposes a hook for subscribing to store updates. It uses the connect function to bind the store state and reducers to the module

/store/index.js

import { init } from '@rematch/core'
import connectStore from '@spon/connect'

const store = init({
	models: {
		count: {
			state: 0, // initial state
			reducers: {
				increment(state, payload) {
					return state + payload
				}
			}
		}
	}
})

// this creates a function that is used to bind modules to the store
export const connect = connectStore(store)

export default store

/behaviours/example

import { connect } from '@/store'
import { domEvents, withPlugins } from '@spon/plugins'

function counter({ plugins: { addEvents }, store, subscribe }) {
	const node = document.getElementById('value')

	addEvents({
		'click button': () => {
			store.dispatch.increment(1)
		}
	})

	subscribe(
		({ current }) => {
			node.textContent = current.count
		},
		['count'] // dependencies
	)
}

const mapState = store => {
	return {
		count: store.count
	}
}
const mapDispatch = ({ count }) => ({ ...count })

export default withPlugins(domEvents)(
	connect({ mapState, mapDispatch })(counter)
)

FAQs

Package last updated on 03 Oct 2019

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