-
Notifications
You must be signed in to change notification settings - Fork 34
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
Proposal: Drop streamProps
helper function
#405
Comments
Just started using frintjs in an application I am building and while I like this proposal on the surface, how would the following translate to this new approach? Basic idea being that I need grab the export default observe(function (app, props$) {
const store = app.get('store');
return streamProps({
id: null,
counter: -1
})
.set(
Observable.combineLatest(
props$,
store.getState$()
),
([ props, state ]) => {
const { id } = props
const { counter } = state;
return counter[id];
}
)
.get$();
})(renderFn); |
@dremonkey: glad to know you are using it! Something like this should help you reach your desired result: import React from 'react';
import { compose } from 'frint-props-react';
import { withDefaults, withObservable } from 'frint-props';
import { distinctUntilChanged, map } from 'rxjs/operators';
function MyComponent(props) {
const { yourOwnPropKey } = props;
return <p></p>;
}
export default compose(
withDefaults({
yourOwnPropKey: null,
}),
withObservable(
(app, props$) => props$.pipe(
// let's only stream further if props passed from parent have changed
distinctUntilChanged(),
// we have latest props, and we stream the store's state
props => app.get('store').getState$().pipe(
// before passing state further, we extract only a portion of it
map(state => state.counter[props.id]),
),
// we have what we need, and shape it to a props-compatible object
desiredValue => ({
yourOwnPropKey: desiredValue,
}),
),
),
)(MyComponent); You could also use export default observe((app, props$) => {
return props$.pipe(
distinctUntilChanged(),
switchMap(
props => app.get('store').getState$().pipe(
map(state => ({
yourOwnPropKey: state.counter[props.id]),
}),
)
),
);
})(MyComponent); |
@fahad19 That's very helpful. Thank you! |
Background
observe
higher-order component that is shipped fromfrint-react
streamProps
Introducing
frint-props
We also developed
frint-props
andfrint-props-react
recently, which is done in a separate repository here: https://github.com/frintjs/frint-propsThe features that they provide makes existing
streamProps
redundant.We can of course have a safe migration path for this.
Examples
Same result, one with
streamProps
, the other withfrint-props
.With
streamProps
With
frint-props
Further reading
The text was updated successfully, but these errors were encountered: