All Projects → pupper → pupper-react

pupper / pupper-react

Licence: Unlicense license
React components for Pupper

Programming Languages

javascript
184084 projects - #8 most used programming language

d005d89e-ff25-4450-9119-aa56ff0d8949

Codacy Badge

Pupper stands for "PHP Plus React" (PPR > Pupper). The goal is to make a Framework that takes the best of both technologies and makes them communicate bi-directionnaly.

See pupper on Github for more information

API

SocketProvider

SocketProvider takes a WebSocket as a prop and hydrates it to its child components.

It can automatically bind them by using the bindTo prop, that can be overwritten.

const globalSocket = new WebSocket('ws://127.0.0.1/ws');

<SocketProvider socket={globalSocket} bindTo='customEvent'>
    
    {/* becomes <CustomComponent socket={globalSocket} bindTo='customEvent'/> */}
    <CustomComponent/>
       
    {/* becomes <OtherComponent socket={globalSocket} bindTo='otherEvent'/> */}
    <CustomComponent bindTo='otherEvent' />
    
</SocketProvider>

withSocket

withSocket ables a component to be provided by SocketProvider.

export default withSocket(MyComponent)

EventListener

EventListener is the Component you want to extend whenever you want to receive updates for an event.

Overwrite its onData method to define what to do with the value.

class CustomerLogger extends EventListener {
    onData(value) {
        console.log('Customer has logged', value);
    }
}

// Usage
<CustomerLogger bindTo='customerHasLogged'/>

EventDispatcher

EventDispatcher is the Component you want to extend whenever you want to send event updates.

Invoke its onSubmit method to send a new event with its toSubmit prop value.

class LoginButton extends EventDispatcher {
    render() {
        return <button onClick={this.onSubmit}>Submit</button>
    }
}

// Usage
<LoginButton toSubmit={this.state.customerId} bindTo='customerHasLogged'/>

Credits

License

Unlicense. Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].