Giter Site home page Giter Site logo

react-broadcast's People

Contributors

andarist avatar greenkeeperio-bot avatar j-f1 avatar kevin940726 avatar mjackson avatar pakerstrand avatar ryanflorence avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-broadcast's Issues

RFC: Add support for changing <Subscriber channel>?

It should be possible to change the channel in a subscriber, but it's not implemented yet. Is this something that people need? For now I think I'll put an invariant there that prevents people from trying to change it.

Add <Subscriber quiet> prop to avoid invariant when rendered out of context

Currently, if you render a <Subscriber> out of context it'll throw an invariant. This is similar to the context API itself, where if you try to use this.context.cupcakes outside the appropriate context you'll get an error.

What we don't have is a way for users to opt-out of the invariant when they're not rendered in the right context. This would be the equivalent of the isRequired functionality currently available to consumers of the context API through contextTypes.

The idea would be to add <Subscriber quiet> to opt-out of the invariant in these situations.

Make API less verbose

The readme shows you a lot of boilerplate code, that you have to write before you can start using the library. However, it could be much simpler with the same effect:

import { createContextProvider, createContextHOC } from 'react-context-emission'

const GeoProvider = createContextProvider('geo', next => {
   navigator.geolocation.watchPosition(next)
})
const withGeo = createContextHOC('geo')

Then you can start using this immediately, no need to write generic React.Component code every time

const App = withGeo(({geo}) => {
   if(geo) {
        return <dl>
            <dt>latitude</dt>
            <dd>{geo.coords.latitude}</dd>
            <dt>longitude</dt>
            <dd>{geo.coords.longitude}</dd>
          </dl>
    else {
         return <p>Getting geoposition...</p>
    }
})

ReactDOM.render(<GeoProvider><App /></GeoProvider>, container)

Thank you for the library! The idea is awesome, but I think that API could be better.

createContext: uid clash when developing npm linked packages

Each npm linked package has its own set of node_modules, therefore there might be multiple copies of react-broadcasts required by an app (all with the same version). Each of them ofc maintains its own uid counter but broadcasts is a shared key on legacy context and all those copies override what the put in context.

Don't have better idea on how to deal with it than randomizing broadcasts key (at least in development), thoughts? Can prepare a PR handling this if you find it worthwhile.

Use the special string only for context key

It seems like the only place we should use the special string is for the key on context, to avoid clashes with others. Everything else we can make generic.

const [ Emitter, Subscriber ] = createContextEmission('keyOnContext')

<Emitter value={someValue}/>

<Subscriber>
{value => (
  // ...
)}
</Subscriber>

Just seems like less docs to do it this way, no?

Subscriber optional context

Thanks for this library.

I'm wanting to use Subscriber, but in a place where the context (broadcast) is not always set. In this case I would like to use either a default prop, or simply undefined.

Currently I can't do this, and I get this error:
browser.js:40 Uncaught Error: <Subscriber channel="filterStore"> must be rendered in the context of a <Broadcast channel="filterStore">

Subscriber rendered outside of context of a Broadcast but inside of another Broadcast for a different concern

@mjackson, @ryanflorence thanks for the lib!

I'm getting an error because in occasions I wrap certain components with <Subscriber> when they are not descendants of <Broadcast>. I know this was discussed (#6) and fixed but I'm still getting this error:

Uncaught Error: <Subscriber channel="concernX"> must be rendered in the context of a <Broadcast channel="concernX">

I should mention that I use different <Broadcast> - <Subscriber> pairs for different concerns.

For example:

<Broadcast channel="concern1">
  <Broadcast channel="concern2">
    {whatever}
  </Broadcast>
  <Subscriber channel="concern2">
    {whateverElse}
  </Subscriber>
</Broadcast>

There's a problem in <Subscriber channel="concern2"> because this.context.broadcasts exists but not for concern2.

Is this the expected behaviour? Any workaround?

Updating from the outside

Is there a way to update the broadcast value from a separate file. Perhaps inside a method? Having a broadcast set with channel and value, I think I'll like something like:

// different class
import { Broadcast } from 'react-broadcast'

class Foo extend React.Component {
  someMethod() {
    Broadcast.update({name: 'Brendan Eich'})
  }
}

Is it worth to mark library as deprecated?

Context API was finally stabilized in React 16.3 and is based on react-broadcast.

Therefore, it's worth to mark this as deprecate or at least state clearly in docs that React Context API provide the same interface.

What do you think? Is there any reason not to deprecate 'react-broadcast'?

Changelog?

Is there a list of changes anywhere? Thanks!

โœŒ๏ธ

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.