Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prism-observable

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prism-observable

Утилита для использования redux-observable вместе с prism. Оборачивает epics, позволяя им работать с префикснутыми actions, а также с частью store, относящейся к компоненту.

  • 2.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

prism-observable

This package fixes the problem of multiple same epics. You can read more about epics here https://redux-observable.js.org. By default epics can listen certain actions, but if those actions came from same components epic could not differ it.

That's why we should pass some identifier (prefix or smth else) to totaly define correct action.

Install

$ npm install prism-observable --save

Usage

import { combineEpics } from 'redux-observable';
import { wrapEpic } from 'prism-observable';

// the target epic 
const fetchCities = action$ => {
	return action$.ofType('FETCH')
		.debounceTime(300)		
	    .switchMap(({ url }) =>
	      ajax({url: url, crossDomain: true})	        
			.map(result => ({
				type: 'FULFILL',
				payload: result.response
			}))			
	    );
}


// the function identifier
// it listen all possible actions apply to regexp
const getPrefix = action => {
	const match = action.type.match(/^routes\.[\d].(from|to)/);
	return match ? match[0] : null;
}

export default combineEpics(
	wrapEpic(fetchCities, getPrefix),
);

The function getPrefix makes possible to listen actions such as routes.1.from.FETCH, routes.0.to.FETCH... After epic makes it's deal wrapEpic wraps the output action by appending the prefix. It case routes.1.from.FETCH you will get routes.1.from.FULFILL

API

The signature is wrapEpic(epic, getPrefix, selector);

NameTypeRequiredDescription
epicfunctiontrueThe target epic to wrap
getPrefix`functionstring`true
selectorfunctionfalseThe state slice selector for the second epic argument.

FAQs

Package last updated on 28 Jun 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc