django-redux


Namedjango-redux JSON
Version 0.0.13 PyPI version JSON
download
home_page
SummaryA re-usable bridge between Django channels and Redux Edit
upload_time2017-06-28 21:23:52
maintainer
docs_urlNone
author
requires_python
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Django Redux
=============================

A re-usable bridge between Django channels and Redux.

Quickstart
----------

::

    $ pip install django_redux
    $ npm install django_redux

Create a file called `engine.py` for your project::

    from django_redux import action, ReduxConsumer


    class MyConsumer(ReduxConsumer):

        def connect(self, message, **kwargs):
            if message.user.is_authenticated():
                self.send({
                    'type': 'SET_USER',
                    'user': {
                        'username': self.message.user.username,
                    }
                })

        # This method will be called when the `INCREMENT_COUNTER` action gets
        # fired from the JS via the reduxBridge (see below).
        @action('INCREMENT_COUNTER')
        def incr_counter(self, message):
            self.group_send('broadcast', {'type': 'INCREMENTED_COUNTER', 'incrementBy': message['incrementBy']})

Create a file called `routing.py` for your project::

    from channels.routing import route_class
    from .consumers import MyConsumer

    channel_routing = [
        route_class(MyConsumer),
    ]

in your settings::

    CHANNEL_LAYERS = {
        'default': {
            'BACKEND': 'asgi_redis.RedisChannelLayer',
            'CONFIG': {
                'hosts': [('localhost', 6379)],
            },
            'ROUTING': 'myproject.routing.channel_routing',
        },
    }

In your js entry point::

    import React from 'react';

    import { render } from 'react-dom';
    import { Provider } from 'react-redux';
    import { createStore, } from 'redux';

    import reducer from '../reducers';
    import Root from '../containers/Root.react';

    import { reduxBridge } from 'django_redux';

    const store = createStore(
      reducer,
    );


    reduxBridge.connect();
    reduxBridge.listen(store);

    render(
      <Provider store={store}>
        <Root />
      </Provider>,
      document.getElementById('root')
    );

To send an action from redux::

    import { createAction } from 'redux-actions';

    import ActionTypes from './constants';
    import { reduxBridge } from 'django_redux';


    export const incrementCounter = createAction(ActionTypes.INCREMENT_COUNTER, (incrementBy) => {
      reduxBridge.send({
        type: ActionTypes.INCREMENT_COUNTER,
        incrementBy
      });
    });

To send an action from channels::

    from django_redux import send_action

    send_action('mygroup', {
        'type': 'ACTION_NAME',
        'payload': {'any': 'thing'},
    })

TODO:

* Tests
    * ``send_action``
* Data binding
* Docs
    * ``ReduxConsumer.get_control_channel``
    * Multiplexing

Credits
-------

Most of this code is adapted from `johnpaulett/channel_chat <https://github.com/johnpaulett/channel_chat>`_.



            

Raw data

            {
    "maintainer": "", 
    "docs_url": null, 
    "requires_python": "", 
    "maintainer_email": "", 
    "cheesecake_code_kwalitee_id": null, 
    "keywords": "", 
    "upload_time": "2017-06-28 21:23:52", 
    "author": "", 
    "home_page": "", 
    "download_url": "https://pypi.python.org/packages/79/9f/1ba408f3451b1cebd4629404e8f8e79a19edb879b1ea51c4b13c3f0897e4/django_redux-0.0.13.tar.gz", 
    "platform": "", 
    "version": "0.0.13", 
    "cheesecake_documentation_id": null, 
    "description": "Django Redux\n=============================\n\nA re-usable bridge between Django channels and Redux.\n\nQuickstart\n----------\n\n::\n\n    $ pip install django_redux\n    $ npm install django_redux\n\nCreate a file called `engine.py` for your project::\n\n    from django_redux import action, ReduxConsumer\n\n\n    class MyConsumer(ReduxConsumer):\n\n        def connect(self, message, **kwargs):\n            if message.user.is_authenticated():\n                self.send({\n                    'type': 'SET_USER',\n                    'user': {\n                        'username': self.message.user.username,\n                    }\n                })\n\n        # This method will be called when the `INCREMENT_COUNTER` action gets\n        # fired from the JS via the reduxBridge (see below).\n        @action('INCREMENT_COUNTER')\n        def incr_counter(self, message):\n            self.group_send('broadcast', {'type': 'INCREMENTED_COUNTER', 'incrementBy': message['incrementBy']})\n\nCreate a file called `routing.py` for your project::\n\n    from channels.routing import route_class\n    from .consumers import MyConsumer\n\n    channel_routing = [\n        route_class(MyConsumer),\n    ]\n\nin your settings::\n\n    CHANNEL_LAYERS = {\n        'default': {\n            'BACKEND': 'asgi_redis.RedisChannelLayer',\n            'CONFIG': {\n                'hosts': [('localhost', 6379)],\n            },\n            'ROUTING': 'myproject.routing.channel_routing',\n        },\n    }\n\nIn your js entry point::\n\n    import React from 'react';\n\n    import { render } from 'react-dom';\n    import { Provider } from 'react-redux';\n    import { createStore, } from 'redux';\n\n    import reducer from '../reducers';\n    import Root from '../containers/Root.react';\n\n    import { reduxBridge } from 'django_redux';\n\n    const store = createStore(\n      reducer,\n    );\n\n\n    reduxBridge.connect();\n    reduxBridge.listen(store);\n\n    render(\n      <Provider store={store}>\n        <Root />\n      </Provider>,\n      document.getElementById('root')\n    );\n\nTo send an action from redux::\n\n    import { createAction } from 'redux-actions';\n\n    import ActionTypes from './constants';\n    import { reduxBridge } from 'django_redux';\n\n\n    export const incrementCounter = createAction(ActionTypes.INCREMENT_COUNTER, (incrementBy) => {\n      reduxBridge.send({\n        type: ActionTypes.INCREMENT_COUNTER,\n        incrementBy\n      });\n    });\n\nTo send an action from channels::\n\n    from django_redux import send_action\n\n    send_action('mygroup', {\n        'type': 'ACTION_NAME',\n        'payload': {'any': 'thing'},\n    })\n\nTODO:\n\n* Tests\n    * ``send_action``\n* Data binding\n* Docs\n    * ``ReduxConsumer.get_control_channel``\n    * Multiplexing\n\nCredits\n-------\n\nMost of this code is adapted from `johnpaulett/channel_chat <https://github.com/johnpaulett/channel_chat>`_.\n\n\n", 
    "lcname": "django-redux", 
    "bugtrack_url": null, 
    "github": false, 
    "name": "django-redux", 
    "license": "", 
    "summary": "A re-usable bridge between Django channels and Redux Edit", 
    "split_keywords": [], 
    "author_email": "", 
    "urls": [
        {
            "has_sig": false, 
            "upload_time": "2017-06-28T21:23:49", 
            "comment_text": "", 
            "python_version": "py2.py3", 
            "url": "https://pypi.python.org/packages/6e/35/9cee2a82febbb038b20428276bb60162d25200b10b4825a02c688e153d1d/django_redux-0.0.13-py2.py3-none-any.whl", 
            "md5_digest": "f0bf256ec176f0bf6dba5cb80395499b", 
            "downloads": 0, 
            "filename": "django_redux-0.0.13-py2.py3-none-any.whl", 
            "packagetype": "bdist_wheel", 
            "path": "6e/35/9cee2a82febbb038b20428276bb60162d25200b10b4825a02c688e153d1d/django_redux-0.0.13-py2.py3-none-any.whl", 
            "size": 136796
        }, 
        {
            "has_sig": false, 
            "upload_time": "2017-06-28T21:23:52", 
            "comment_text": "", 
            "python_version": "source", 
            "url": "https://pypi.python.org/packages/79/9f/1ba408f3451b1cebd4629404e8f8e79a19edb879b1ea51c4b13c3f0897e4/django_redux-0.0.13.tar.gz", 
            "md5_digest": "351ae974ca8a64a3dbd59b3aa21ec2b4", 
            "downloads": 0, 
            "filename": "django_redux-0.0.13.tar.gz", 
            "packagetype": "sdist", 
            "path": "79/9f/1ba408f3451b1cebd4629404e8f8e79a19edb879b1ea51c4b13c3f0897e4/django_redux-0.0.13.tar.gz", 
            "size": 9231
        }
    ], 
    "_id": null, 
    "cheesecake_installability_id": null
}