DEV Community

Discussion on: Preact Composition API

Collapse
 
porfirioribeiro profile image
Porfirio

I like that concept also, it can solve some issues, but may introduce others.

Using named exports alow for better tree-shaking and better minification, making all composition functions optional.
The way you specify it needs to create a object with all the functions binded.

Thanks for bringing this to discussion. We can find the pros and cons of both approachs and decide where to go!

Collapse
 
mindplay profile image
Rasmus Schultz

Using named exports alow for better tree-shaking and better minification, making all composition functions optional.

True.

But it doesn't have to be OOP - that was just an example.

We can do the same thing with functions:

const Comp = createComponent(component => {
    const filterRef = ref(component, 'ALL');
    const filteredItems = watch(
        component,
        [props => props.items, filterRef],
        ([items, filter]) => filterItems(items, filter)
    );
    return () => <ItemList items={filteredItems.value} />;
});

My only point is don't hide your dependencies in global state.

Thread Thread
 
porfirioribeiro profile image
Porfirio

I see your ideas.
Would be nice to discuss this better. Could you post your concern on the PR github.com/preactjs/preact/pull/1923
or on Preact Slack
preact.slack.com/

Thread Thread
 
mindplay profile image
Rasmus Schultz

Done 🙂