frintjs / frint-props

Compose reactive props in FrintJS applications
https://frint.js.org
MIT License
12 stars 1 forks source link

frint-props-react: create higher-order component #7

Closed fahad19 closed 6 years ago

fahad19 commented 6 years ago

The higher-order component will use frint-react's observe internally:

// frint-props-react/hoc.js

import { observe } from 'frint-react';
import { compose } from 'frint-props';

function hoc(...args) {
  return observe(function (app, props$) {
    return compose(...args)(app, props$);
  });
}

If there is a better name for the HoC, please suggest it here.

See usage example here: https://github.com/frintjs/frint-props#usage-with-react

fahad19 commented 6 years ago

Depends on #6

viacheslaff commented 6 years ago

I think that hoc name can be improved. Higher order component is a term describing a way to organize code. It says nothing about it's functionality, so it's hard to get this aspect from naming. Besides, if there'll be two HOCs at some point, naming will become even less clear.

I would suggest wrapper for a name. Which is not ideal, but I think it's better than hoc. Maybe we can think of something that this thing does: it composes and provides all kind of props and creates a new component with them.

fahad19 commented 6 years ago

thanks @viacheslaff! I don't like the hoc name either 😬

I remember @DzmitryKukharuk suggesting produce.

viacheslaff commented 6 years ago

IHMO, sound vague to me as well. I'm afraid we might not be able to get away with one word. I also think it should be a noun. What do you think of componentWithProps or wrapperWithProps or propsProvider?

fahad19 commented 6 years ago

I am gonna stay away from the name provider as much as possible for components. we already have a concept of "Providers" inside Apps. can lead to confusion in component layer.

viacheslaff commented 6 years ago

True

viacheslaff commented 6 years ago

Maybe we can think of injectProps and then adjust with... methods to fromProps, fromStore, fromDefault etc.

fahad19 commented 6 years ago

It's a difficult thing to name this component. can't seem to be fully convinced with any of the suggestions by all of us combined :-/

the API of frint-props is inspired by Recompose actually. and they popularized with* functions (and higher-order components) in the React community.

according to the current state of master branch, we are adopting a convention like this:

nunorfpt commented 6 years ago

some ideas: capsule, garment, binder, mantle, canopy

fahad19 commented 6 years ago

is it gonna be too controversial to have a compose higher-order component? 😬

import { compose } from 'frint-props';
import { compose } from 'frint-props-react';
viacheslaff commented 6 years ago

Is there gonna be the case when those two are used in one file? I don't think there will be clashes. The use cases I see:

fahad19 commented 6 years ago

@viacheslaff: that is correct, I don't see any clash of usage in a single module anywhere.

but that being said, I personally don't like using the name compose across two packages either. but we also can't seem to find any suitable name yet.

this is the only blocker we have now for publishing to npm.

viacheslaff commented 6 years ago

but that being said, I personally don't like using the name compose across two packages either.

But this is what packages are for.