gabrielguerrero / ngrx-traits

NGRX Traits is a library to help you compose and reuse state logic in your angular app. There is two versions, @ngrx-traits/signals supports ngrx-signals, and @ngrx-traits/{core, common} supports ngrx.
MIT License
50 stars 3 forks source link

merge traits #3

Closed gabrielguerrero closed 2 years ago

gabrielguerrero commented 3 years ago

This is a place holder to find a way to best merge a set of traits into one Possible examples

export const traits = createEntityFeatureFactory(
  {
     products: [
       addLoadEntities<Product>(),
      addSingleSelection<Product>(),
     addSort<Product>()
  ],
   orders: [
       addLoadEntities<Order>(),
      addSingleSelection<Order>(),
     addSort<Order>()
  ]
  }
);

Another possible way

export const traits = createEntityFeatureFactory(
....
   addProperty('products', addLoadEntities<Product>(),
      addSingleSelection<Product>(),
     addSort<Product>()),    
addProperty('orders',  addLoadEntities<Order>(),
      addSingleSelection<Order>(),
     addSort<Order>())

First one I think is easier to implement , second one is harder but more flexible so might be more useful, there are state shapes that the second can do but not the first

gabrielguerrero commented 2 years ago

this was implement in a different way with the combineEntityFeatureFactory, mixEntityFeatureFactory and addEntityFeaturesProperties