django-redux


Namedjango-redux JSON
Version 0.0.12 PyPI version JSON
download
home_page
SummaryA re-usable bridge between Django channels and Redux Edit
upload_time2017-04-03 20:50:35
maintainer
docs_urlNone
author
requires_python
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
Coveralis test coverage No Coveralis.
            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-04-03 20:50:35", 
    "author": "", 
    "home_page": "", 
    "download_url": "https://pypi.python.org/packages/01/96/f1f67329b048b8575170c8aabe2036d7ea0c37614ca75e6fb8ff8c8bcae3/django_redux-0.0.12.tar.gz", 
    "platform": "", 
    "version": "0.0.12", 
    "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-04-03T20:50:33", 
            "comment_text": "", 
            "python_version": "py2.py3", 
            "url": "https://pypi.python.org/packages/bd/6b/33289654c3908fa88e35960ad676cc125b5ebf4887cab676b5d785fb7884/django_redux-0.0.12-py2.py3-none-any.whl", 
            "md5_digest": "341ac3aad9974ae95725a610898bb9d2", 
            "downloads": 0, 
            "filename": "django_redux-0.0.12-py2.py3-none-any.whl", 
            "packagetype": "bdist_wheel", 
            "path": "bd/6b/33289654c3908fa88e35960ad676cc125b5ebf4887cab676b5d785fb7884/django_redux-0.0.12-py2.py3-none-any.whl", 
            "size": 136795
        }, 
        {
            "has_sig": false, 
            "upload_time": "2017-04-03T20:50:35", 
            "comment_text": "", 
            "python_version": "source", 
            "url": "https://pypi.python.org/packages/01/96/f1f67329b048b8575170c8aabe2036d7ea0c37614ca75e6fb8ff8c8bcae3/django_redux-0.0.12.tar.gz", 
            "md5_digest": "9dc2d04c11caf4a6acacf453fd51e82a", 
            "downloads": 0, 
            "filename": "django_redux-0.0.12.tar.gz", 
            "packagetype": "sdist", 
            "path": "01/96/f1f67329b048b8575170c8aabe2036d7ea0c37614ca75e6fb8ff8c8bcae3/django_redux-0.0.12.tar.gz", 
            "size": 9236
        }
    ], 
    "_id": null, 
    "cheesecake_installability_id": null
}