Skip to content

Detect functions and implicitly wrap in O? #30

@JAForbes

Description

@JAForbes

Proposal

// OLD:
O({ layoutEnabled: O( x => !x ), loggedIn: false })

// NEW:
O({ layoutEnabled: x => !x, loggedIn: false })

The primary use case of O is for state management not monkey patching, and it would be convenient to not need to manually wrap functions in O when detecting that a value is a function is 95% likely to be intended to be a patching function for that key instead.

This would enable patterns like meiosis to have one call site for patchinko in the entire application, and component code need not know how their patch is being processed as they don't need to import patchinko to do a patch on a key'd value.

Background

@barneycarroll we've discussed this before I think. The original reason you wrote patchinko was to monkey patch mutably an existing API.

It seems to me, the immutable version of patchinko has a completely different value proposition. It's an easy to use reducer in the context of meiosis/actor model style apps. And those state objects that are being reduced rarely store functions within the state tree (I think we could call that an anti pattern).

Normally I'm not in favour of implicit behaviour, but that's kind of the value proposition of O so I figure why not complete the circle.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions