npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

contentful-redux

v1.0.0

Published

Contentful sync API implementation for redux/reselect

Downloads

17

Readme

contentful-redux

Build Status codecov npm Greenkeeper badge

This library provides an implementation of the Contentful sync API for redux and reselect. contentful-redux handles the complete synchronization workflow (including cyclic link resolution, localization, and incremental syncing) and lets you consume your contents from Contentful as easy-to-use selectors.

If you are not already familiar with redux (and reselect), you should familiarize yourself with those first before trying to integrate contentful-redux into your project.

Installation

contentful-redux is provided as a collection of CommonJS modules, which can be installed using npm:

npm install --save contententful@5 contentful-redux

or using yarn:

yarn add contentful@5 contentful-redux

Usage

  1. Setup contentful-redux (contentful.js):
import { createClient } from 'contentful';
import contentfulRedux from 'contentfulRedux';

export const { actions, reducer, middleware, selectors } = contentfulRedux({
    createClient,
    space: 'YOUR_SPACE_ID',
    accessToken: 'YOUR_ACCESS_TOKEN',
    stateSelector: state => state.contentful
});
  1. Include the contentful reducer in your reducer:
import { combineReducers } from 'redux';
import { reducer as contentful } from './contentful';

export const reducer = combineReducers({
    contentful,
    // your other reducers
});
  1. Include the contentful middleware in your redux store configuration:
import { applyMiddleware, createStore } from 'redux';
import { middleware as contentful } from './contentful';

export const configureStore = () => {
    return createStore(reducer, null, applyMiddleware(contentful));
};
  1. Derive your reselect selectors from the base selectors provided by contentful-redux:
import { createSelector } from 'reselect';
import { selectors } from './contentful';

export const myModelEntities = createSelector(
    selectors.entries, selectors.contentTypes,
    (entries, contentTypes) => entries.filter(each => each.__contentType__ === contentTypes.myModel)
);
  1. Dispatch a sync action whenever you want:
import { actions } from './contentful';
dispatch(actions.sync());

API Documentation

contentfulRedux(options)

| Option | Required | Default | Description | | ---------------- | --------- | ------- | ----------- | | accessToken | yes | - | Your contentful CDA access token | | clientParams | no | {} | Additional arguments to be passed to createClient | | createClient | yes | - | The desired variant of the contentful.js client factory method | | localeSelector | no | () => null | A selector returning the locale to be used, e.g.(state) => state.currentLocale| | space | yes | - | The id of the contentful space to by synced | | stateSelector | yes | - | A selector returning the portion of the state which is managed by the contentful-redux reducer, e.g.(state) => state.contentful |

Action creators

The following redux action creators are provided by contentful-redux:

sync([spaceId])

| Argument | Required | Default | Description | | ----------| --------- | -------------- | ----------- | | spaceId | no | options.space | The id of the space to be synced. There must be a middleware installed wich is registered with the same space id |

Selectors

The following reselect selectors are provided by contentful-redux:

| Selector | Returns | Description | | --------------- | ------------ | ----------- | | assets | array | A list of all known assets in the contentful space | | contentTypes | object | A map from content type ids to the meta information about the corresponding content type | | defaultLocale | object | The locale which is defined as default of the contentful space | | entries | array | A list of all known entries in the contentful space | | isSyncing | boolean | true while a sync operation is in progress | | lastSync | object | Meta-information about the results of the last sync attempt | | locales | array | The locales which are defined for the contentful space | | space | object | Meta-information about your contentful space |

Changelog

License

This software is licensed under the MIT License. View the license.

Copyright © 2018 Leo Schweizer