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

redux-wpapi

Package Overview
Dependencies
Maintainers
3
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-wpapi

Wordpress integration Redux middleware based on node-wpapi.

  • 1.3.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
3
Weekly downloads
 
Created
Source

redux-wpapi

npm version Build Status

A node-wpapi integration for a Redux based Application.

How it Works

This library exposes node-wpapi instance through the actionCreator callAPI. The resulting action is interpreted in the middleware, doing so by resolving the request and controlling the reducer through actions.

Installation

npm install --save redux-wpapi

Then, to enable ReduxWPAPI, use applyMiddleware() and combineReducers():

import reducers from './reducers';
import ReduxWPAPI from 'redux-wpapi';

const { reducer: wp, middleware } = new ReduxWPAPI({ /* … */ });
const store = createStore(
  // the reducer must be placed at the root of the state as `wp`
  // so the selector knows where state lives in
  { ...reducers, wp },
  applyMiddleware(middleware)
);

Usage

import React from 'react';
import { wp, selectRequest, ResponseStatus } from 'redux-wpapi';
import { connect } from 'react-redux';

export class HomePage extends React.Component {
  static loadData(props) {
    return props.callAPI(
      // The name where the request state will be placed
      'HomePagePosts',
      // A callback where wpapi instance is injected
      api =>
      api.posts()
      .page(props.page)
      .perPage(props.perPage)
    );
  }

  componentWillMount() {
    HomePage.loadData(this.props);
  }

  componentWillReceiveProps(props) {
    HomePage.loadData(props);
  }

  render() {
    const { status, data: posts } = this.props.request;

    if (!posts) {
      switch (status) {
          case ResponseStatus.pending: return <div>Loading…</div>;
          case ResponseStatus.rejected: return <div>An error has occurred</div>;
      }
    }

    return (
      <div>
        {!posts.length ? <NoPostFound /> : <PostList posts={posts} />}
      </div>
    );
  }
}

export default connect({
  request: selectRequest('HomePagePosts'),
}, { callAPI })(HomePage);

Contributions

All contributions are welcome, and very much appreciated.

We are preparing some helper documents to facilitate the process (hopefully), but for now we're following the these guidelines:

  • Be reasonable
  • Give as much detailed information as you can
  • Keep it as short as possible
  • Let the code talk

Must have's

Every Pull Request must have the following:

  • Unit tests for any functionality that's exposed to the end user.
  • An entry in the CHANGELOG.md file.

FAQs

Package last updated on 16 Dec 2016

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