React Wire
Tiny and Fast library for react components communications
Install
$ npm install react-wire
Reference
listen(event: string)
A method decorator that listening specified event
@ { }
dispatch(event: string, ...args)
A function that dispatches specified event
with provided arguments
;
trigger(event: string)
A method decorator that triggers a dispatching specified event
with method result as an event first argument
@ { return 'message'; }
the same as
;
Usage examples
A simple snackbar example
// Snackbar.js;; state = display: false message: '' ; @ { ; this; thistimerId = ; }; @ { this; } { const display message = thisstate; return <div className=display ? 'snackbar--shown' : 'snackbar--hidden'> <button onClick=thiscloseSnackbar>X</button> message </div> ; }
// Menu.js;; state = counter: 0 ; @ { this; } { ; } { const counter = thisstate; return <div> Snackbar closed: counter times <input ref= thisinput = input /> <button onClick=thisshowSnackbar>Show snackbar</button> <button onClick=thiscloseSnackbar>Close snackbar</button> </div> ; }
// index.js;;;; ;
License
The MIT License Copyright (c) 2016-2018 Ivan Zakharchenko