GithubHelp home page GithubHelp logo

philiptranp / redux-ghost Goto Github PK

View Code? Open in Web Editor NEW

This project forked from oliverbenns/redux-ghost

0.0 1.0 0.0 23 KB

Redux reducer and actions to get posts, users and tags from a Ghost Blog Public Api (https://ghost.org)

License: MIT License

HTML 11.31% CSS 2.24% JavaScript 86.45%

redux-ghost's Introduction

redux-ghost

npm version

Installation

npm install --save redux-ghost

Getting Started

Step 1

Enable your Ghost blog to expose a public api following this tutorial. Make note of your client_id, client_secret and host (e.g. http://localhost:2368).

Step 2

For a quick test, follow the example, otherwise configure redux ghost with your credentials in step 1 and give the Ghost reducer to redux. Ensure you also include the thunk middleware.

import { createStore, combineReducers, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import ReduxGhost, { reducer as ghostReducer } from 'redux-ghost';

ReduxGhost.config({
  host: '', // e.g. http://localhost:2368
  clientId: '', // e.g. ghost-frontend
  clientSecret: '', // e.g. 4837a41df11b
});

const rootReducer = combineReducers({
  blog: ghostReducer,
});

const store = createStore(rootReducer, null, applyMiddleware(thunk));

Step 3

Set up your store as you normally would, and fire off those actions.

import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { actions } from 'redux-ghost';

const App = ({ actions, blog }) => {
  return (
    <div>
      <button onClick={() => actions.getPosts()}>Load Posts</button>
      {blog.posts.data && blog.posts.data.map((post, index) => (
        <div key={index}>
          <h2>{post.title}</h2>
          <p>Published on: {post.published_at}</p>
          <p>Slug: {post.slug}</p>
        </div>
      ))}
    </div>
  );
}

const mapStateToProps = ({ blog }) => ({
  blog,
});

const mapDispatchToProps = (dispatch) => ({
  actions: bindActionCreators(actions, dispatch)
});

export default connect(
  mapStateToProps,
  mapDispatchToProps,
)(App);

Actions

Call your actions how you like, I prefer binding mine to props using bindActionCreators.

Actions available:

Action Arguments
getPosts options (object)
getPost id (string / integer), options (object)
getTags options (object)
getTag id (string / integer), options (object)
getUsers options (object)
getUser id (string / integer), options (object)
reset

Development

Build

Run nvm use; redux-ghost; npm install; npm run build. Any further file changes will require another npm run build.

Example

nvm use; npm link; cd example; npm link redux-ghost; npm install; npm start.

Open http://localhost:3030/.

Any new builds will automatically refresh the example with updates.

redux-ghost's People

Contributors

oliverbenns avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.