Skip to content
This repository has been archived by the owner on Jun 4, 2019. It is now read-only.

API changes #9

Open
lilactown opened this issue Jan 14, 2017 · 0 comments
Open

API changes #9

lilactown opened this issue Jan 14, 2017 · 0 comments

Comments

@lilactown
Copy link
Owner

lilactown commented Jan 14, 2017

Proposal 1: observeComponent returns observable

Right now, creating the ObservableComponent and obtaining the observable attached to the component is done in two steps:

// create observable component
const MyComponent = observeComponent('div')('onClick');

// obtain the observable attached to it
const myObs$ = fromComponent(MyComponent);

observeComponent could be changed to instead return both the component we are observing, as well as the observable attached:

const { component, observable } = observeComponent('div')('onClick');

This would remove the need for fromComponent, however it would require users to use object destructuring and renaming:

const {
  component: MyComponent,
  observable: myObs$,
} = observeComponent('div')('onClick');

const {
  component: OtherComponent,
  observable: otherObs$
} = observeComponent('input')('onChange');

It could also be done by returning an array instead of an object to avoid the verbosity of renaming the object properties:

const [MyComponent, myObs$] = observeComponent('div')('onClick');

However, this would be less ergonomic for people who may be utilizing this library without es2015+.

Pros:

  • Reduces API surface (only one function!)
  • Removes the need to mutate the wrapped React component by attaching the observable as a property
  • Removes fromComponent function, which is slightly redundant and potentially confusing to new users.

Cons:

  • Relies on ES2015+ syntax to be really ergonomic
  • Would be a breaking change
  • Loses similarity to obtaining observables from other event-producing objects in most libraries (Rx.Observable.from(), Kefir.fromCallback/fromEvents/fromPoll, etc...)
@lilactown lilactown changed the title Return observable instead of using fromComponent Return observable from observeComponent instead of using fromComponent Jan 14, 2017
@lilactown lilactown changed the title Return observable from observeComponent instead of using fromComponent API changes Jan 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant