Skip to content

Commit

Permalink
release 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidC committed Jul 18, 2016
1 parent f7aa45d commit 6316495
Show file tree
Hide file tree
Showing 16 changed files with 529 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"presets": ["react", "es2015", "stage-0"],
"plugins": [
"transform-decorators-legacy",
"transform-runtime"
]
}
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/*
webpack.config*.js
build/*
prepublish.js
dist/*
lib/*
36 changes: 36 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"extends": "airbnb",
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true,
"generators": false,
"objectLiteralDuplicateProperties": false
}
},
"rules": {
"no-console": [ 1, { "allow": ["warn", "error"] } ],
"no-multi-spaces": [ 2, { "exceptions": {
"VariableDeclarator": true,
"ImportDeclaration": true
}}],
"key-spacing": [2, { "align": "value" }],
"space-in-parens": "off",
"no-warning-comments": [2, { "terms": ["todo", "fixme"], "location": "anywhere" }],
"max-len": [1, 100, 2, {"ignoreUrls": true, "ignoreComments": true}],
"no-multiple-empty-lines": [1, {"max": 3}],
"object-shorthand": 0,
"new-cap": [2, {"capIsNewExceptions": ["Router"]}],
"no-param-reassign": 0,
"array-bracket-spacing": ["error", "always"],
"no-underscore-dangle": 0,
"react/jsx-curly-spacing": 0,
"react/jsx-first-prop-new-line": 0,
"spaced-comment": 0,
"jsx-a11y/img-uses-alt": 0,
"jsx-a11y/redundant-alt": 0,
"jsx-a11y/valid-aria-role": 0
}
}
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
*.env
*.log
npm-debug.log
.DS_Store
dist
lib
coverage
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
All notable changes are described on the [Releases](https://github.com/dacz/rxr-react/releases) page.
14 changes: 14 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Contributor Code of Conduct

As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.

We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.

Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.

This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)

68 changes: 68 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Contributing
We are open to, and grateful for, any contributions made by the community. By contributing to rxr-react, you agree to abide by the [code of conduct](https://github.com/dacz/rxr-react/blob/master/CODE_OF_CONDUCT.md).

## Reporting Issues and Asking Questions
Before opening an issue, please search the [issue tracker](https://github.com/dacz/rxr-react/issues) to make sure your issue hasn't already been reported.

## Development

Visit the [Issue tracker](https://github.com/dacz/rxr-react/issues) to find a list of open issues that need attention.

Fork, then clone the repo:
```
git clone https://github.com/your-username/rxr-react.git
```

### Building

Running the `build` task will create both a CommonJS module-per-module build and a UMD build.
```
npm run build
```

To create just a CommonJS module-per-module build:
```
npm run build:lib
```

To create just a UMD build:
```
npm run build:umd
npm run build:umd:min
```

### Testing and Linting

To run the tests:
```
npm run test
```

To continuously watch and run tests, run the following:
```
npm run test:watch
```

To perform linting with `eslint`, run the following:
```
npm run lint
```

###New Features

Please open an issue with a proposal for a new feature or refactoring before starting on the work. We don't want you to waste your efforts on a pull request that we won't want to accept.


## Submitting Changes

* Open a new issue in the [Issue tracker](https://github.com/dacz/rxr-react/issues).
* Fork the repo.
* Create a new feature branch based off the `master` branch.
* Make sure all tests pass and there are no linting errors.
* Submit a pull request, referencing any issues it addresses.

Please try to keep your pull request focused in scope and avoid including unrelated commits.

After you have submitted your pull request, we'll try to get back to you as soon as possible. We may suggest some changes or improvements.

Thank you for contributing!
56 changes: 55 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,56 @@
# rxr-react
React bindings for rxr (RxJS the Redux way)

React bindings for [rxr](https://github.com/dacz/rxr) (RxJS the Redux way).

> Use [RxJS](https://github.com/ReactiveX/rxjs) with React the way similar to Redux. If you know Redux, rxr introduces very similar concept using into RxJS. It allows to **rewrite Redux app** to use pure RxJS with rxr fast with **most of the main code intact**. This is huge benefit when you want just play with something you already have. To learn, to play... ;)
>
>I'm sure there are different ways how to use RxJS with React. Redux is very popular (and I like it a lot!) and it established some code structure and thinking about the app. Applying RxJS the Redux way has a lot of benefits. We may build on what we know and therefore it's easier to learn RxJS.
... [read more on rxr](https://github.com/dacz/rxr).


## Basic usage

```javascript
import React from 'react';
import { render } from 'react-dom';
import Rx from 'rxjs';
import { createState } from 'rxr';
import { Provider } from 'rxr-react';

const userSelected$ = new Rx.Subject;
const userReducer$ = userSelected$
.map(val => (state) => ({ ...state, itemsSelected: state.itemsSelected.push(val) }));
const initialState = { itemsSelected: [] };

const state$ = createState(userReducer$, initialState);

render(
<Provider state$={ state$ }>
<App />
</Provider>, document.getElementById('index')
);
```

and to connect the component...

```javascript
import { connectWithState } from 'rxr-react';
import MyContainer from './MyContainer';
// lets's suppose that our userSelected$ stream was bound with next()
// (see rxr createPushMessageFunctions) and is part of userActions
// structure
import userActions from './userActions';

const selector = (state) => ({
itemsSelected: state.itemsSelected,
userSelected: myMessageStreams.userSelected,
});

const MyHoCContainer = connectWithState(selector)(MyContainer);
```

The props `MyContainer` gets are `itemsSelected` (array to display) and `userSelected` - action that is supposed to be invoked somehow like `... onClick={ userSelected('itemA') } ...`.


### I'll add more details here very soon.
99 changes: 99 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"name": "rxr-react",
"version": "0.1.0",
"description": "React bindings for rxr - RxJS",
"main": "lib/index.js",
"files": [
"dist",
"lib",
"src"
],
"scripts": {
"clean": "rimraf lib dist es",
"lint": "eslint src test",
"test": "cross-env NODE_ENV=test ava",
"test:watch": "npm test -- --watch -v",
"check:src": "npm run lint && npm run test",
"build:lib": "babel src --out-dir lib",
"build:umd": "cross-env NODE_ENV=development webpack src/index.js dist/rxr-react.js",
"build:umd:min": "cross-env NODE_ENV=production webpack src/index.js dist/rxr-react.min.js",
"build": "npm run build:lib && npm run build:umd && npm run build:umd:min && node ./prepublish",
"prepublish": "npm run clean && npm run build"
},
"repository": {
"type": "git",
"url": "https://github.com/dacz/rxr-react.git"
},
"keywords": [
"react",
"reactjs",
"rxjs",
"reactive",
"rxr",
"redux",
"reducer",
"state",
"functional"
],
"author": "David Cizek <david@origamica.com> (https://twitter.com/dadc)",
"license": "MIT",
"bugs": {
"url": "https://github.com/dacz/rxr-react/issues"
},
"homepage": "https://github.com/dacz/rxr-react",
"ava": {
"files": [
"test/**/test-*.js"
],
"require": [
"babel-register"
],
"babel": "inherit"
},
"devDependencies": {
"ava": "^0.15.2",
"babel": "^6.5.2",
"babel-cli": "^6.10.1",
"babel-core": "^6.10.4",
"babel-eslint": "^6.1.2",
"babel-loader": "^6.2.4",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-runtime": "^6.9.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.11.1",
"babel-preset-stage-0": "^6.5.0",
"babel-register": "^6.9.0",
"cross-env": "^2.0.0",
"enzyme": "^2.4.1",
"es3ify": "^0.2.2",
"eslint": "^3.1.0",
"eslint-config-airbnb": "^9.0.1",
"eslint-plugin-import": "^1.10.3",
"eslint-plugin-jsx-a11y": "^2.0.1",
"eslint-plugin-react": "^5.2.2",
"jsdom": "^9.4.1",
"react": "^15.2.1",
"react-addons-test-utils": "^15.2.1",
"react-dom": "^15.2.1",
"rimraf": "^2.5.3",
"webpack": "^1.13.1"
},
"dependencies": {
"is-observable": "^0.2.0",
"rxjs": "^5.0.0-beta.10",
"rxjs-es": "^5.0.0-beta.10",
"symbol-observable": "^1.0.1"
},
"peerDependencies": {
"react": "^15.2.1"
},
"npmName": "rxr-react",
"npmFileMap": [
{
"basePath": "/dist/",
"files": [
"*.js"
]
}
]
}
25 changes: 25 additions & 0 deletions prepublish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var glob = require('glob')
var fs = require('fs')
var es3ify = require('es3ify')

glob('./@(lib|dist)/**/*.js', function (err, files) {
if (err) {
throw err
}

files.forEach(function (file) {
fs.readFile(file, 'utf8', function (err, data) {
if (err) {
throw err
}

fs.writeFile(file, es3ify.transform(data), function (err) {
if (err) {
throw err
}

console.log('es3ified ' + file) // eslint-disable-line no-console
})
})
})
})
26 changes: 26 additions & 0 deletions src/components/Provider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Component, PropTypes, Children } from 'react';

export default class Provider extends Component {

static propTypes = {
state$: PropTypes.object.isRequired,
children: PropTypes.element.isRequired,
};

static childContextTypes = {
state$: PropTypes.object.isRequired,
}

constructor(props, context) {
super(props, context);
this.state$ = props.state$;
}

getChildContext() {
return { state$: this.state$ };
}

render() {
return Children.only(this.props.children);
}
}
34 changes: 34 additions & 0 deletions src/components/connectWithState.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React, { PropTypes } from 'react';
import deepEqual from 'deep-equal';

const connectWithState = (selector = (state) => state) => (WrappedComponent) =>
class ConnectWithState extends React.Component {

static contextTypes = {
state$: PropTypes.object,
};

constructor(props, context) {
super(props, context);
this.state$ = context.state$;
}

componentWillMount() {
this.subscription = this.state$
.map(selector)
.distinctUntilChanged((a, b) => deepEqual(a, b))
.subscribe(::this.setState);
}

componentWillUnmount() {
this.subscription.unsubscribe();
}

render() {
return (
<WrappedComponent {...this.state} {...this.props} />
);
}
};

export default connectWithState;
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Provider from './components/Provider';
import connectWithState from './components/connectWithState';

export { Provider, connectWithState };
Loading

0 comments on commit 6316495

Please sign in to comment.