Socket
Book a DemoInstallSign in
Socket

redux-resx-feathers-middleware

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-resx-feathers-middleware

Feathers middleware for redux-resx

latest
Source
npmnpm
Version
0.3.0
Version published
Maintainers
1
Created
Source

redux-resx-feathers-middleware

Middleware for redux-resx using feathers-client.

npm install --save redux-resx-feathers-middleware

Usage

import resxMiddleware from 'redux-resx-feathers-middleware';

import feathers from 'feathers-client';
import rest from 'feathers-client/rest';

import reducers from './reducers';

// Setup your feathers app - probably in a different file
const app = feathers().configure(rest('/api').fetch(fetch));

export default function createAppStore() {
  return createStore(
    reducers,
    compose(
      applyMiddleware(
        resxMiddleware(app)
      ),
      window.devToolsExtension ? window.devToolsExtension() : (f) => f
    )
  );
}

Websocket support

Not yet - all we'd need to add is websocket events handlers that fire receiver actions

Pagination (v0.1.0)

WARNING: This API may change. I'd like feedback on it :)

Pagination is handled by installing a resultReducer on your resource.

import pagination from 'redux-resx-feathers-middleware';

const paginate = pagination({ perPage: 10 });
export const users = createResource({
  name: '@resx/USER',
  url: '/users',
  // Add this to paginated endpoints
  resultReducers: {
    find: paginate,
  },
});

This will add a pagination object to your resource state:

Here is an exmaple when using it in a component:

import React, { PropTypes } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';

import { users } from '../../resources';

export const UsersPage = React.createClass({
  displayName: 'UsersPage',

  propTypes: {
    findUsers: PropTypes.func.isRequired,
    dispatch: PropTypes.func.isRequired,
    users: PropTypes.object.isRequired,
  },

  componentWillMount() {
    const { findUsers } = this.props;
    findUsers({ query: { roles: 'admin' } });
  },

  render() {
    const { users: { items, pagination }, dispatch } = this.props;

    // *** Important bit here **
    // Dispatch pagination.next to fetch the next items.
    // The result of this call will be concatenated onto items.
    const next = () => dispatch(pagination.next);
    return (
      <div>
        <h1>Emails:</h1>
        {JSON.stringify(items.map(i => i.email))}
        {pagination ? <button disabled={!pagination.hasMore} onClick={next}>Next</button> : null}
      </div>
    );
  },
});

function mapStateToProps(state) {
  return {
    users: users.selector(state),
  };
}

const { find: findUsers } = users.actions;

export default connect(mapStateToProps, {
  findUsers,
})(UsersPage);

FAQs

Package last updated on 23 Oct 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