0.3.3 • Published 8 years ago

ryan v0.3.3

Weekly downloads
15
License
MIT
Repository
github
Last release
8 years ago

Installation

npm install ryan

Idea

The goal is to provide contextTypes through higher-order components so you can write your code like this:

import React from 'react';
import ReactDOM from 'react-dom';
import {connect} from 'ryan';

@connect
class App extends React.Component {
    render() {
        // store methods available at all times
        this.context.store.getUsername()
        // state available at all times
        return <div>{this.context.state.username}</div>
    }
}


/**
 * But first we need to wrap our root component (App in this case)
 * around a ContextProvider before rendering
 * @returns {Component}
 */
import React from 'react';
import {contextTypes} from 'ryan';

class ContextProvider extends React.Component {

    static childContextTypes = contextTypes;

    getChildContext() {
        return this.props.context;
    }

    render() {
        return this.props && this.props.children
    }
}

/**
 * Then we put it all together.
 * Initialize stores & inject state into our context
 */
const context = {
    state: window.__STATE, // an observable mobx object
    store: {
        setUsername(username) {
            window.__STATE.username = username;
        },
        getUsername() {
            return window.__STATE.username;
        }
    }
}

// Render HTML on the browser
ReactDOM.render(<ContextProvider context={context}>
    <App/>
</ContextProvider>, document.getElementById('content'));

Author

https://github.com/nightwolfz
0.3.3

8 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.3

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago

0.0.9

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago

1.0.28

8 years ago

1.0.27

8 years ago

1.0.26

8 years ago

1.0.25

8 years ago

1.0.24

8 years ago

1.0.23

8 years ago

1.0.22

8 years ago

1.0.21

8 years ago

1.0.20

8 years ago

1.0.19

8 years ago

1.0.18

8 years ago

1.0.17

8 years ago

1.0.16

8 years ago

1.0.15

8 years ago

1.0.14

8 years ago

1.0.13

8 years ago

1.0.12

9 years ago

1.0.11

9 years ago

1.0.10

9 years ago

1.0.9

9 years ago

1.0.8

9 years ago

1.0.7

9 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago