HowTo: Dynamic number of Filter.OnChange expressions
See original GitHub issueI have a situation where I am matching a variable number of values before a rule can run it’s ‘update’.
What I want is a way to pass this variable number of values into a the Filter.OnChange
call?
This is what I have
plateModule plate = null;
IEnumerable<DoubleVariable> values = null;
When()
.Match<plateModule>(() => plate) // Find the owner
.Query(() => values, x => x
.Match<DoubleVariable>( // Start a list of vars
dv => dv.OwnerPart == plate, // check that this belongs to the owner
dv => dv.ValueSet // check that it has a value set
)
.Collect() // aggregate the list
.Where(c => c.Count() == plate.DoubleVariables.Count) // check that all have been accounted for
);
and then want to place the values into the Filter.OnChange(....
with monitoring the DoubleVariable.Value
field.
e.g. is this valid ?
plate.DoubleVariables.ForEach(dv => Filter()
.OnChange(() => dv.Value)
);
Or is there an Actual way ?
Especially as the plate.
will be null
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
angularjs - dynamically change the filter expression
I want to dynamically assign a different filter expression based on the user. So user2 will have {isCommon: 'M2'}. angularjs · Share.
Read more >Building a Dynamic Filter with ES6 JavaScript | by Tyler Burdsall
Conclusion. With this knowledge you can build a dynamic filter depending on any of the user's inputs. Plus, you now have a flexible...
Read more >Filter on a data source with a dynamic number of f...
In my app, users can select a number of different text terms to add them as filters. Then the user can search a...
Read more >Create a dynamic filter option
Enter a number to designate the placement of this dynamic filter option in the filter option choice list. Roles, Select the role a...
Read more >Designer Desktop: Dynamic filtering with different parameters
Hey everyone. I am trying to dynamically filter a date based on some previous formulas validation. Here's a visual example:
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
OnChange accepts one or more keys to monitor for changes. But the number of keys must be known at rule compile time. Since you have an unbound collection, you need to flatten it to a single key to pass it to the OnChange filter. I showed you flattening into a string as a naive example of flattening a collection to a single immutable value. It’s also not that bad from performance perspective, since this string (or whatever flattened value you produce) will only be generated when the filter condition is evaluated, which is when the rule already produced a full match. Imagine what would the engine need to do to support OnChange for collections. It would need to compare two snapshots of that collection, element by element, to determine if anything changed. That is exactly what you can do by implementing a ChangeKey class that wraps your collection and implements IEquatable. That’s also in spirit similar to what you were proposing with the CreateOnChanges snippet.
And then in the filter:
And as before, you can wrap this in an extension method to read better.
Thanks for taking time out for this…
That was a “copy and paste” and forgetting to “tidy up” error !
That is correct, to try an emulate “Late updates” of multiple variables later on.
Agreed.
OK.
And I put this before the next part:
apple2.DoubleVariables.First().SetValue(2);
And Now I see the Equality being fired. Now I understand why I was not seeing the firing, because internally (I am assuming) in the NRules compiler, it is being “Very” efficient in the way it needs to call the filters, and hence the need to not calling the Do functionality if it has only been evaluated once…
Again thanks for going through this with me.