All Projects → tkh44 → react-nes

tkh44 / react-nes

Licence: MIT license
React components for nes

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-nes

animation-wrapper-view
Declarative animations with imperative controls for RN/RNW.
Stars: ✭ 53 (+65.63%)
Mutual labels:  react-components, declarative
hydra-hpp
Hydra Hot Potato Player (game)
Stars: ✭ 12 (-62.5%)
Mutual labels:  sockets
socketwrapper
Async/Sync networking library including UDP, TCP and TLS/TCP socket classes written in C++ 17.
Stars: ✭ 33 (+3.13%)
Mutual labels:  sockets
nests
NES Emulator Written in TypeScript/React
Stars: ✭ 91 (+184.38%)
Mutual labels:  nes
6502.Net
A .Net-based Cross-Assembler for Several 8-Bit Microprocessors
Stars: ✭ 44 (+37.5%)
Mutual labels:  nes
react-abstract-autocomplete
Bring-Your-Own-UI autocomplete / mentions component for React.
Stars: ✭ 15 (-53.12%)
Mutual labels:  react-components
openNES-Snake
Simple rebuilt of the classic Snake game for the NES in C using the cc65 cross compiler.
Stars: ✭ 18 (-43.75%)
Mutual labels:  nes
react-color
🎨 Is a tiny color picker widget component for React apps.
Stars: ✭ 50 (+56.25%)
Mutual labels:  react-components
mobius-gui
🎨 Reactive & Stream & Driver based UI framework build on Mobius Utils, equipped with neumorphism-derived & utility-first styles.
Stars: ✭ 43 (+34.38%)
Mutual labels:  declarative
shopify-node-react-app
Shopify paid app in Node.js & React.js that connects to a store and lets merchants select products to automatically discount them in the Shopify admin interface.
Stars: ✭ 29 (-9.37%)
Mutual labels:  react-components
react-sync
A declarative approach to fetching data via a React higher order component
Stars: ✭ 18 (-43.75%)
Mutual labels:  declarative
fusion-components
A collection of React Components built with Emotion.js
Stars: ✭ 13 (-59.37%)
Mutual labels:  react-components
stg-for-nes
Simple STG for NES
Stars: ✭ 18 (-43.75%)
Mutual labels:  nes
rsuite.github.io
React Suite documentation site. The library will stop updating. For documentation related issues, please visit https://github.com/rsuite/rsuite/tree/master/docs.
Stars: ✭ 41 (+28.13%)
Mutual labels:  react-components
mern-admin-panel
Admin-panel using ReactJs, ExpressJs, NodeJs, MongoDB and Bootstrap
Stars: ✭ 84 (+162.5%)
Mutual labels:  react-components
retrore
A curated list of original and reverse-engineered vintage 6502 game sourcecode.
Stars: ✭ 22 (-31.25%)
Mutual labels:  nes
react-image-and-background-image-fade
React Image and Background Image Preloader and Fade in. Load those images in smooth!
Stars: ✭ 26 (-18.75%)
Mutual labels:  react-components
react-pluto
A package of small but beautiful React components from the planet, Pluto. 🔵 Get minimal components for your React based applications 😍
Stars: ✭ 17 (-46.87%)
Mutual labels:  react-components
hapi-cli
CLI to build API with Hapi, mongodb and mongoose. Work with Hapi V17.
Stars: ✭ 36 (+12.5%)
Mutual labels:  hapijs
react-component-maker
react-component-maker
Stars: ✭ 32 (+0%)
Mutual labels:  react-components

react-nes

npm version Build Status codecov

React components for nes

npm install -S react-nes

API

Please refer to the nes docs if you have questions about what each prop does.

nes API documentation

Components

ClientProvider

Props

client (nesClient) : nes client instance

onError (function) : client.onError

onConnect (function) : client.onConnect

onDisconnect (function) client.onDisconnect

onUpdate (function) client.onUpdate

children (element) : accepts a single child

Example
const client = new Nes.Client('http://localhost')
const App = ({ auth }) => {
  return (
    <ClientProvider
      client={client}
      onError={console.error}
      onConnect={() => console.log('Global connected')}
      onDisconnect={() => console.log('disconnected')}
      onUpdate={(message) => console.log('Update', message)}
    >
      <div>
        {/* ... */}
      </div>
    </ClientProvider>
  )
}

Connect

Props

auth (object|string) : client auth

delay (number)

maxDelay (number)

retries (number)

timeout (number)

onConnect (function) : the server response callback

children (function) : child callback with signature function({ connecting, connected, error, overrideReconnectionAuth, connect, disconnect })

Example
const MyComponent = ({ auth }) => {
  return (
    <Connect
      auth={auth}
      onConnect={() => console.log('Local connected')}
    >
      {({ connecting, connected, error, overrideReconnectionAuth, connect, disconnect }) => {
        console.log(connecting, connected, error, overrideReconnectionAuth, connect, disconnect)
      }}
    </Connect>
  )
}

withNesClient (HoC)

inject the client into a component's props

Example
const ComponentWithClient = withNesClient(({ client }) => {
  return (
    <SomeComponentThatNeedsClient client={client}/>
  )
})

Request

Props

lazy (object|string) : client auth

path (string)

method (string)

headers (object)

payload (object)

onResponse (function) : the callback method using the signature function(err, payload, statusCode, headers)

children (function) : child callback with signature function({ fetching, payload, error, statusCode, headers, request })

Example
const Room = ({ id }) => {
  return (
    <Request path={`/room/${id}`}>
      {({ fetching, payload, error, statusCode }) => {
        return (
          <div>
            {statusCode !== 200 && <Redirect path={`/${statusCode}`}/>}
            {fetching && <Loader/>}
            {payload && <Content id={id} data={payload}/>}
            {error && <Error error={error}/>}
          </div>
        )
      }}
    </Request>
  )
}

Subscribe

Props

path (string)

handler (function)

onSubscribe (function) : the callback function called when the subscription request was received by the server or failed to transmit

onUnsubscribe (function) : the callback function called when the unsubscribe request was received by the server or failed to transmit

children (function) : child callback with signature function({ subscribing, subscribed, error, getSubscriptions, subscribe, unsubscribe })

Example
const MySubscribedComponent = ({ connected, id }) => {
  if (!connected) return (<Loader/>)

  return (
    <Subscribe path={`/room/${this.props.id}`} handler={this.handleSub}>
      {({ subscribing, subscribed, error }) => {
        return (
          <div>
            {subscribing && <Loader/>}
            {subscribed && <Content id={id}/>}
            {error && <Error error={error}/>}
          </div>
        )
      }}
    </Subscribe>
  )
}

Realistic Example

// Using react-router and redux...
class RoomWrapper extends Component {
  render () {
    return (
      <Connect
        auth={auth}
        onConnect={() => console.log('Local connected')}
      >
        {({ connecting, connected, error, overrideReconnectionAuth, connect, disconnect }) => {
          return (
            <Room
              connected={connected}
              id={this.props.params.id}
              room={this.props.room}
              handleRoomSubUpdate={this.handleRoomSubUpdate}
              handleRoomResponse={this.handleRoomResponse}
            />
          )
        }}
      </Connect>
    )
  }

  handleRoomSubUpdate = (message, flags) => {
    this.props.dispatch({ type: 'room/SUB_UPDATE', payload: { message, flags } })
  }

  handleRoomResponse = (error, payload, statusCode, headers) => {
    this.props.dispatch({ type: 'room/RESPONSE', payload, error, meta: { statusCode, headers } })
  }
}

const Room = ({ connected, handleRoomSubUpdate, handleRoomResponse, id, room = {} }) => {
  if (!connected) return (<Loader/>)

  return (
    <Subscribe path={`/room/${id}`} handler={handleRoomSubUpdate}>
      {({ subscribing, subscribed, subError }) => {
        return <Request path={`/room/${id}`} onResponse={handleRoomResponse}>
          {({ fetching, statusCode, reqError }) => {
            if (subscribing || fetching) return (<Loader/>)

            if (subError || reqError) return (<Error error={subError || reqError}/>)

            if (statusCode && statusCode !== 200) return (<Redirect to={`/${statusCode}`}/>)

            return (<RoomContent id={id} room={room} subscribed={subscribed}/>)
          }}
        </Request>
      }}
    </Subscribe>
  )
}

const client = new Nes.Client('http://api.mystartup.com')
const App = ({ auth, dispatch }) => {
  return (
    <ClientProvider
      client={client}
      onError={
        (err) => dispatch({ type: 'nes/Error', payload: err })
      }
      onConnect={
        () => dispatch({ type: 'nes/Connected' })
      }
      onDisconnect={
        (willReconnect, log) => dispatch({ type: 'nes/Disconnect', payload: { willReconnect, log } })
      }
      onUpdate={
        (message) => dispatch({ type: 'nes/Message', payload: message })
      }
    >
      <RoomWrapper auth={auth}/>
    </ClientProvider>
  )
}
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].