Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

redux-scripts-manager

nhardy23MIT0.4.2TypeScript support: included

Manage dynamic script loading with Redux

redux, scripts, manager, dynamic, script, loading

readme

Redux Scripts Manager

npm version CircleCI Coverage Status

This library allows for the management of dynamic script loading on the client with Redux. This allows you to conditionally load scripts that don't always need to load on your site, like third party APIs for social media or maps.

Peer Dependencies

Requires:

Usage

// Reducers file

import { combineReducers } from 'redux';
import { reducer as scripts } from 'redux-scripts-manager';


export default combineReducers({
  scripts, // If you're giving this an alternate key, make sure you use that key when you register with the store

  // Your reducers
});
// Client entry point

import scriptsManager from 'redux-scripts-manager';


scriptsManager(store); // Register with the store. Optionally takes a second parameter for the key in the store
// React component

import { loadScript } from 'redux-scripts-manager';

const src = '//example.org/path/to/script.js';

@connect(null, { loadScript })
export default class Thing Extends React.Component {
  componentDidMount() {
    this.props.loadScript(src).then(() => {
      // Do Some stuff
    });
  }
}
// React component

import { loadScript } from 'redux-scripts-manager';

// For scripts which provide a JSONP callback parameter
const src = cb => `//example.org/path/to/script.js?onload=${cb}`;

@connect(null, { loadScript })
export default class Thing Extends React.Component {
  componentDidMount() {
    this.props.loadScript(src).then(() => {
      // Do Some stuff
    });
  }
}
// React component

import { loadScript } from 'redux-scripts-manager';

const src = '//example.org/path/to/script.js';

@connect(null, { loadScript })
export default class Thing Extends React.Component {
  componentDidMount() {
    // For scripts that use a callback on `window`
    this.props.loadScript(src, 'onApiLoaded').then(() => {
      // Do Some stuff
    });
  }
}

changelog

Changelog

[0.4.2] - 2018-09-23

Fixed

  • Fixed module alias not being transpiled

[0.4.1] - 2018-09-23

Fixed

  • Fixed "main" entrypoint in package.json

[0.4.0] - 2018-09-23

Changed

  • Ported to TypeScript

[0.3.3] - 2017-10-06

Fixed

  • Babel target environment

[0.3.2] - 2017-10-06

Fixed

  • Fixed broken linting/tests

[0.3.1] - 2017-10-06

Changed

  • Updated devDependencies (this may cause issues with older versions of Node)

[0.3.0] - 2017-10-06

Added

  • loadScript(src, callbackName) action creator can now take an optional second parameter for specific JSONP callbacks

[0.2.0] - 2016-11-27

Added

  • loadScript(src) action creator can now take a single-parameter Function for JSONP callbacks

[0.1.1] - 2016-10-22

Changed

  • Updated build status badge style

[0.1.0] - 2016-10-22

Added

  • loadScript(src) action creator now returns a Promise that resolves when the script has loaded
  • redux is now specified in peerDependencies
  • redux-thunk is now a peer dependency
  • Changelog

[0.0.1] - 2016-10-15

Initial release