Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: invalid object where a stream was expected (rxjs 6.2.0) #131

Closed
tukwan opened this issue Jun 1, 2018 · 4 comments
Closed

TypeError: invalid object where a stream was expected (rxjs 6.2.0) #131

tukwan opened this issue Jun 1, 2018 · 4 comments

Comments

@tukwan
Copy link

tukwan commented Jun 1, 2018

Hi,
I'm getting Error using toStream function.

TypeError: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
screen shot 2018-06-01 at 12 54 10

Code: (breaks on Observable.from)

  componentDidMount() {
    this.sub$ = Observable.from(toStream(() => this.props.store.slug))
      .switchMap(slug => fetchSlug(slug))
      .catch((err, $) => {
        this.props.history.push('/')
        return Observable.empty()
      })
      .subscribe(({ name }) => {
          this.props.store.setSearch(name)
          this.props.store.setHideDropdown(true)
        }
      })
    this.props.store.setSlug(this.props.match.params.slug)
  }

Works 100% on Chrome.
Breaks sometimes on safari & firefox.
Breaks consistently on iOS safari.

Used app dependencies:

"rxjs": "^6.2.0",
"rxjs-compat": "^6.2.0",
"mobx": "^4.2.1",
"mobx-react": "^5.1.2",
"mobx-utils": "^4.0.1",

Any ideas what cause the problem?

@tukwan tukwan changed the title TypeError: invalid object where a stream was expected (RxJS 6.2) TypeError: invalid object where a stream was expected (rxjs 6.2.0) Jun 1, 2018
@mweststrate
Copy link
Member

mweststrate commented Jun 1, 2018 via email

@tukwan tukwan closed this as completed Jun 12, 2018
@WearyMonkey
Copy link

WearyMonkey commented Sep 17, 2018

Just got hit by this. Can confirm it's not a mobx-utils bug, but https://github.com/benlesh/symbol-observable being a non-pure pony.

We're using symbol-observable (via redux), Rxjs and mobx-utils.

The behaviour in our build was:

  1. Rxjs ponyfill imported, Symbol.observable not available so '@@observable' used.
  2. symbol-observable imported via redux, Symbol.observable set.
  3. mobx-utils imported, Symbol.observable is now available so used.

Rxjs and mobx-util observables are no longer compatible with each other.

Related: benlesh/symbol-observable#38

Work around:
Import symbol-observable before all other modules.

@tukwan
Copy link
Author

tukwan commented Sep 17, 2018

@WearyMonkey
I've solved it by using .create rxjs method.

import { computed } from 'mobx'
import { Observable } from 'rxjs/Observable'
import { Observer } from 'rxjs/Observer'

export const toStream = <T>(expression: () => T): Observable<T> =>
  Observable.create((observer: Observer<T>) => {
    const computedValue = computed(expression)
    return computedValue.observe(change => observer.next(change.newValue))
  })

@tukwan tukwan reopened this Sep 17, 2018
@tukwan tukwan closed this as completed Sep 17, 2018
@TimonVS
Copy link

TimonVS commented Jan 25, 2023

I've created a Stackblitz to reproduce the issue: https://stackblitz.com/edit/typescript-5le5kn?file=index.ts (make sure to open the console). See #300 (comment) for more context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants