Skip to content

📚 [DOCS]: Share your custom State Operators here! #926

Closed
@markwhitfeld

Description

@markwhitfeld

NGXS Provides some default state operators but the real power is in the pattern it offers.
Please share your custom state operators here, someone else may find them useful.
If they are general purpose, logical and popular then they might even get added to the default operators in the lib!

RULES to keep this thread clean:

  • Please only submit one comment per operator (pointless comments will be deleted).
  • Vote for the operators using the standard emojis (please don't add needless comments)
  • In your comment please provide the following:
    • A description of the use case for the operator
    • A usage example of the operator as code
    • A link to a github gist with your operator and preferably tests too!
    • Any other useful information

PS. What makes a good operator?

  • It only returns a new state if changes are needed. For Example:
    • if there is a predicate and it is not matched, then just return the original state
    • if the new value equals the old value, then just return the original state
  • It is composable (you can pass other operators in, if applicable)
    • if a parameter requires a value then provide the option of passing an operator or a value (where it makes sense - ie. for updateItem but not for insertItem)
  • These are good examples:

PS. If you have no clue what this is about read this article.

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionAn issue that discusses design decisions.not an issueAn issue logged that doesn't require fixing (maybe just a question)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions