0.3.3 • Published 9 years ago

ryan v0.3.3

Weekly downloads
15
License
MIT
Repository
github
Last release
9 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

9 years ago

0.3.2

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.0

9 years ago

0.0.9

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago

1.0.28

10 years ago

1.0.27

10 years ago

1.0.26

10 years ago

1.0.25

10 years ago

1.0.24

10 years ago

1.0.23

10 years ago

1.0.22

10 years ago

1.0.21

10 years ago

1.0.20

10 years ago

1.0.19

10 years ago

1.0.18

10 years ago

1.0.17

10 years ago

1.0.16

10 years ago

1.0.15

10 years ago

1.0.14

10 years ago

1.0.13

10 years ago

1.0.12

10 years ago

1.0.11

10 years ago

1.0.10

10 years ago

1.0.9

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago