Skip to content
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

Custom feature builder that receives a function instead of array of features #4678

Open
2 tasks
kobi2294 opened this issue Jan 18, 2025 · 0 comments
Open
2 tasks

Comments

@kobi2294
Copy link

Which @ngrx/* package(s) are relevant/related to the feature request?

signals

Information

A createCustomFeature function. An alternative way to create custom feature that has a few differences from signalStoreFeature.

  1. Instead of receiving an array of feature, it should receive a lambda, from input store to a collection of added members.
  2. The added members should be divided into 4 sections: state, props, methods and hooks
  3. Should also allow to pass additional "prefix" string which will be concatinated to all properties.

It will be used like this:

export function withMyFeature() {
   return createCustomFeature(store => {
         // run some code in injection context, during instantiation of store, using the input store
         // ...
         // return a structure of added members

         return {
               state: {
                              prop: value, 
                              otherProp: otherValue
                         }, 
               props: {
                             computedProp: computed(() => store.x() + store.y())
                }, 
                methods: {
                             doThis: () => {...}
                 }
          }
   });
}

The reason this is required is to support several common use cases with custom features:

  1. Need instance level closure to keep data that is private to the feature
  2. Need to be able to run code on instantiation, that uses the input store
  3. Need to receive a prefix to attach to all added members (current implementation and typing is incredibly complex)

Describe any alternatives/workarounds you're currently using

No response

I would be willing to submit a PR to fix this issue

  • Yes
  • No
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant