0.1.0 • Published 6 years ago

peer-star-react v0.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
6 years ago

peer-star-react

React components for Peer-* apps.

made by Protocol Labs

Install

$ npm install peer-star-react

API

withCollaboration(collaboration)

Higher-order component for creating components that are bound to a specific collaboration.

Example:

import PeerStarApp from 'peer-star-app'
import { withCollaboration } from 'peer-star-react'

function MyComponent ({ collaboration, shared }) {
  // gets collaboration and collaboration.shared as arguments
}

const app = PeerStarApp('my app name')

const collaboration = app.collaborate('collaboration name', 'collaboration type', options)

const MyCollaborativeComponent = withCollaboration(collaboration)(MyComponent)

withCollaborationFromApp(app, name, type, options)

Higher-order component for creating components that are bound to a specific collaboration that will be created from the app.

If options.keys is a string, the keys will be parsed and passed into the collaboration.

Example:

import PeerStarApp from 'peer-star-app'
import { withCollaborationFromApp } from 'peer-star-react'

function MyComponent ({ collaboration, shared }) {
  // gets collaboration and collaboration.shared as arguments
}

const app = PeerStarApp('my app name')

const keys = // some string

const options = { keys }
const MyCollaborativeComponent = withCollaborationFromApp(app, 'collab name', 'collab type', options)(MyComponent)

withCollaborationLiveValue(collaboration)

Higher-order component for creating components that will receive the current collaboration shared value as a property every time it changes.

Example:

import PeerStarApp from 'peer-star-app'
import { withCollaborationLiveValue } from 'peer-star-react'

function MyComponent ({ collaboration, shared, value }) {
  console.log('current value is', value)
  // gets collaboration, collaboration.shared and collaboration.shared.value() as arguments
}

const app = PeerStarApp('my app name')

const collaboration = app.collaborate('collaboration name', 'collaboration type', options)

const MyCollaborativeComponent = withCollaborationLiveValue(collaboration)(MyComponent)

withCollaborationMembership(collaboration)

Higher-order component for creating components that will receive the current collaboration membership as a property every time it changes.

Example:

import PeerStarApp from 'peer-star-app'
import { withCollaborationMembership } from 'peer-star-react'

function MyComponent ({ peers }) {
  // peers is a set

  console.log('current peers are', Array.from(peers))
}

const app = PeerStarApp('my app name')
const collaboration = app.collaborate('collaboration name', 'collaboration type', options)

const MyCollaborativeComponent = withCollaborationLiveValue(collaboration)(MyComponent)

Examples

Start example

$ git clone <this repo>
$ cd peer-star-react
$ npm install
$ npm start

License

MIT