react-redux-secure
v1.0.1
Published
react-redux based package which decides on displaying components based on your rules
Downloads
71
Readme
#React Redux Secure
a package which decides on displaying components based on your rules. I used react-redux connect function codebase
###Installation
npm i -S react-redux-secure
a glimpse on how you handle your stuff would be easy as this. for better clarifications see example folder and run it by.
clone this project then
npm install && npm run example
###rules.js
export default {
comments: () => ({user}, ok, failed) => {
if (user.rules.comments === true)
return ok("comments");
return failed("comments");
},
editComments: () => ({user}, ok, failed) => {
if (user.rules.editComments === true)
return ok("editComments");
return failed("editComments");
}
}
###store.js
import {combineReducers, createStore, applyMiddleware} from "redux";
import {counterReducer} from "./reducers/counterReducer";
import userReducer from "./reducers/userReducer";
import createLogger from "redux-logger";
import {secureReducer} from "react-redux-secure";
export const store = createStore(
combineReducers({
counter: counterReducer,
user: userReducer,
secure: secureReducer(require("../rules").default)
}),
applyMiddleware(createLogger())
);
###Comments.jsx
import React, {Component} from "react";
import {connect} from "react-redux";
import {secure} from "react-redux-secure";
@connect(({counter}) => ({counter}))
@secure(({user}, {comments, editComments}, run) => run(editComments(), comments()))
export default class Comments extends Component {
render() {
return (
<div>comments</div>
);
}
}
###MIT licence