Skip to content

Commit f109ab3

Browse files
committed
INITIAL COMMIT
First version of redux-wp, already functional, but poorly documented. Includes the reducer tests for the actions: - REDUX_WP_API_REQUEST (get, create, update and delete) - REDUX_WP_API_SUCCESS (get)
0 parents  commit f109ab3

18 files changed

+1213
-0
lines changed

.babelrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"presets": [
3+
"es2015",
4+
"stage-1",
5+
]
6+
}

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
indent_style = space
7+
indent_size = 2
8+
9+
[*.md]
10+
indent_style = space
11+
indent_size = 4

.eslintrc

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"root": true,
3+
4+
"parser": "babel-eslint",
5+
6+
"plugins": [
7+
"babel",
8+
"import"
9+
],
10+
11+
"env": {
12+
"browser": true,
13+
"commonjs": true,
14+
"jasmine": true,
15+
"node": false
16+
},
17+
18+
globals: {
19+
__DEV__: false,
20+
process: false
21+
},
22+
23+
"parserOptions": {
24+
"ecmaVersion": 6,
25+
"sourceType": "module",
26+
"ecmaFeatures": {
27+
"jsx": true,
28+
"experimentalObjectRestSpread": true
29+
},
30+
},
31+
32+
"settings": {
33+
"import/extensions": [ ".js" ],
34+
"import/resolver": "node"
35+
},
36+
37+
"extends": [ "airbnb" ],
38+
39+
"rules": {
40+
"no-unused-vars": [2, { "vars": "all", "args": "after-used" }],
41+
"quotes": [2, "single"],
42+
"strict": [2, "never"],
43+
"no-unexpected-multiline": 2,
44+
"no-multi-spaces": [2, {
45+
"exceptions": { "VariableDeclarator": true }
46+
}],
47+
48+
"import/default": 1,
49+
"import/export": 1,
50+
"import/named": 1,
51+
"import/namespace": [1, { "allowComputed": true }],
52+
"import/no-amd": 1,
53+
"import/no-duplicates": 1,
54+
"import/no-extraneous-dependencies": 1,
55+
"import/no-named-as-default": 1,
56+
"import/no-named-as-default-member": 1,
57+
"import/no-unresolved": 2
58+
}
59+
}

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
*.log
3+
node_modules
4+
dist
5+
lib
6+
es

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 log.OSCON
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# redux-wpapi
2+
A [node-wpapi](https://github.com/WP-API/node-wpapi) integration for a Redux based Application.
3+
4+
## How it Works
5+
This library exposes [node-wpapi](https://github.com/WP-API/node-wpapi) instance through the actionCreator [wp](#wp-Action-Creator). The resulting
6+
action is interpreted in [the middleware](#the-middleware), doing so by resolving the request and controlling the reducer through actions.
7+
8+
## Installation
9+
```sh
10+
npm install --save redux-wpapi
11+
```
12+
Then, to enable ReduxWPAPI, use [`applyMiddleware()`](http://redux.js.org/docs/api/applyMiddleware.html) and [`combineReducers()`](http://redux.js.org/docs/api/combineReducers.html):
13+
14+
```js
15+
import reducers from './reducers';
16+
import ReduxWPAPI from 'redux-wpapi';
17+
18+
const { reducer: wp, middleware } = new ReduxWPAPI({ /**/ });
19+
const store = createStore(
20+
// the reducer must be placed at the root of the state as `wp`
21+
// so the selector knows where state lives in
22+
{ ...reducers, wp },
23+
applyMiddleware(middleware)
24+
);
25+
26+
```
27+
28+
## Usage
29+
```js
30+
import React from 'react';
31+
import { wp, selectQuery, ResponseStatus } from 'redux-wpapi';
32+
import { connect } from 'react-redux';
33+
34+
export class HomePage extends React.Component {
35+
componentWillMount() {
36+
this.props.wp(
37+
// The name where the request state will be placed
38+
'HomePagePosts',
39+
// A callback where wpapi instance is injected
40+
api =>
41+
api.posts()
42+
.page(this.props.page)
43+
.perPage(this.props.perPage)
44+
);
45+
}
46+
47+
render() {
48+
const { status, data } = this.props.request;
49+
50+
if (!data) {
51+
switch (status) === ResponseStatus.WAITING) {
52+
return (<div>Loading…</div>)
53+
}
54+
if (status === ResponseStatus.WAITING) {
55+
return (<div>Loading…</div>)
56+
}
57+
}
58+
}
59+
}
60+
61+
export default connect({
62+
request: selectQuery('HomePagePosts'),
63+
}, { wp })(HomePage);
64+
```

package.json

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"name": "redux-wpapi",
3+
"version": "0.1.0",
4+
"description": "Wordpress integration Redux middleware based on node-wpapi.",
5+
"main": "lib/index.js",
6+
"files": [
7+
"dist",
8+
"lib",
9+
"es",
10+
"src"
11+
],
12+
"scripts": {
13+
"clean": "rimraf lib dist es coverage",
14+
"lint": "eslint src test",
15+
"test": "cross-env BABEL_ENV=commonjs mocha --compilers js:babel-register --recursive",
16+
"test:watch": "npm test -- --watch",
17+
"check:src": "npm run lint && npm run test",
18+
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib",
19+
"build:es": "cross-env BABEL_ENV=es babel src --out-dir es",
20+
"build:umd": "cross-env BABEL_ENV=commonjs NODE_ENV=development webpack src/index.js dist/redux-wp.js",
21+
"build:umd:min": "cross-env BABEL_ENV=commonjs NODE_ENV=production webpack src/index.js dist/redux-wp.min.js",
22+
"build": "npm run build:commonjs && npm run build:es && npm run build:umd && npm run build:umd:min",
23+
"prepublish": "npm run clean && npm run check:src && npm run build"
24+
},
25+
"author": "log.OSCON <[email protected]> (http://www.log.pt/)",
26+
"license": "MIT",
27+
"dependencies": {
28+
"immutable": "^3.8.1",
29+
"lodash": "^4.15.0",
30+
"qs": "^6.2.1",
31+
"reselect": "^2.5.3"
32+
},
33+
"devDependencies": {
34+
"babel-cli": "^6.14.0",
35+
"babel-core": "^6.14.0",
36+
"babel-eslint": "^6.1.2",
37+
"babel-loader": "^6.2.5",
38+
"babel-preset-es2015": "^6.14.0",
39+
"babel-preset-stage-1": "^6.13.0",
40+
"babel-register": "^6.14.0",
41+
"cross-env": "^2.0.1",
42+
"eslint": "^3.4.0",
43+
"eslint-config-airbnb": "^10.0.1",
44+
"eslint-plugin-babel": "^3.3.0",
45+
"eslint-plugin-import": "^1.14.0",
46+
"eslint-plugin-jsx-a11y": "^2.2.1",
47+
"eslint-plugin-react": "^6.2.0",
48+
"expect": "^1.20.2",
49+
"mocha": "^3.0.2",
50+
"rimraf": "^2.5.4",
51+
"webpack": "^1.13.2",
52+
"wpapi": "^0.9.1"
53+
}
54+
}

0 commit comments

Comments
 (0)