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

JavaFxObservable.fromObservableList() initial emission #36

Closed
thomasnield opened this issue Jul 2, 2016 · 2 comments
Closed

JavaFxObservable.fromObservableList() initial emission #36

thomasnield opened this issue Jul 2, 2016 · 2 comments

Comments

@thomasnield
Copy link
Collaborator

The JavaFxObservable.fromObservableList() factory should probably emit the ObservableList on subscription as the initial emission. I'm finding myself putting a startsWith() after it to accomplish this all the time.

@thomasnield
Copy link
Collaborator Author

Anybody who doesn't want the initial emission can just use the skip() operator, and this follows the same behavior for factories applied to ObservableValue.

@thomasnield
Copy link
Collaborator Author

Just implemented this for fromObservableList(), fromObservableMap(), and fromObservableSet(). Closing.

    public static <T> Observable<ObservableList<T>> fromObservableList(final ObservableList<T> source) {

        return Observable.create((Observable.OnSubscribe<ObservableList<T>>) subscriber -> {
            ListChangeListener<T> listener = c -> subscriber.onNext(source);
            source.addListener(listener);
            subscriber.add(JavaFxSubscriptions.unsubscribeInEventDispatchThread(() -> source.removeListener(listener)));
        }).startWith(source).subscribeOn(JavaFxScheduler.getInstance());
    }

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

1 participant