redux-script-loader

1.0.0 • Public • Published

redux-script-loader

Contents

  1. Usage
  2. Installation
  3. API
  4. RSL Actions

Usage

A simple example:

import { RSL_LOAD } from 'redux-script-loader';
 
dispatch({
  type: RSL_LOAD,
  payload: 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.min.js',
  success: 'LOAD_SUCCESS',
  fail: 'LOAD_FAIL',
});

Installation

To install from npm:

$ npm install --save redux-script-loader

Then to configure with your redux store:

import { createStore, applyMiddleware } from 'redux';
import { loaderMiddleware } from 'redux-script-loader';
import reducer from './reducers';
 
const store = createStore(reducer, applyMiddleware(loaderMiddleware(document)));

API

RSL_LOAD :: Symbol

A symbol indicating that the action should be handled by the redux-script-loader middleware.

loaderMiddleware :: Function

Returns a redux-compatible middleware. Must be initialised with the document object.

RSL Actions

action.type :: Symbol

Must be RSL_LOAD imported from the redux-script-loader package.

action.payload :: String

The URL from which to load the script. Will be used as the src attribute of the script tag.

action.append :: String | FSA

Action to dispatch when appending the script tag to the document. Can either be a string, or a Flux standard action.

action.success :: String | FSA

Action to dispatch when the appended script tag finishes loading. Equivalent to the load event on the script element.

action.fail :: String | FSA

Action to dispatch when the appended script tag fails to load. Equivalent to the error event on the script element.

Package Sidebar

Install

npm i redux-script-loader

Weekly Downloads

0

Version

1.0.0

License

ISC

Last publish

Collaborators

  • eliascodes