1

I want to select values from an Akita store based on 2 properties, either of which should match the thing I'm looking for.

I started with a simple (added the filterBy [] knowing I'd want to filter on more than one thing) :

this.myQuery.selectAll({
  filterBy: [
    (entity: MyEntityType) => entity.prop1 === thingToMatch 
  ]
}).subscribe((entities) => {})

Which correctly returns entity objects that match the filter. However there are 2 properties onthe entity, either of which may have the value I'm trying to match on. So I took a guess at:

this.myQuery.selectAll({
  filterBy: [
    (entity: MyEntityType) => 
      entity.prop1 === thingToMatch || entity.prop2  === thingToMatch
  ]
}).subscribe((entities) => {})

The second code block there returns no entities, the first returns matching one ok.

I guess I could do a SelectAll and then use TS filtering,

this.myQuery.selectAll().subscribe((entities) => {  
   entities.filter(..... )
});

but I was hoping I could do an OR within the Akita select framework.

What is the correct syntax to do an OR operation on an Akita store select? Should I even be using select() at all?

DaFoot
  • 1,475
  • 8
  • 29
  • 58

1 Answers1

0

I believe an Akita combineQueries would work here.


const filter1 = this.myQuery.selectAll({
  filterBy: [
    (entity: MyEntityType) => entity.prop1 === thingToMatch
  ]
});

const filter2 = this.myQuery.selectAll({
  filterBy: [
    (entity: MyEntityType) => entity.prop2  === thingToMatch
  ]
});

const result$ = combineQueries([filter1, filter2]).subscribe(...) 
SeSq
  • 51
  • 1
  • 6