Rule prioritization and bailing
See original GitHub issueWe need to be able to specify that the list of rules against a property (or tagged rule-set) should be handled sequentially and fail on the first failing rule.
Example scenario: .required().satisfiesRule('slowServerSideCheck')
Do we default to bail (my preferred option) and allow something like .parallel()
, or default to simultaneous and allow '.sequential(),
.bail(),
.bailOnError()` or whatever?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:7 (6 by maintainers)
Top Results From Across the Web
How Do You Prioritize Your Time? 25 Tips for Optimal Time ...
7. Follow the 1-3-5 scheduling rule. · Identify today's top priority from the list. Nothing else matters here. · Determine three medium priorities...
Read more >First Things First: The 5 Secrets to Prioritization - Entrepreneur
1. Beware the seduction of task-based lists. The elements of prioritization are simple: Know what tasks need to be done and rank them...
Read more >Pareto Principle: Using the 80/20 Rule for Priority Management
When you apply the Pareto Principle to prioritization, you shine a light on the activities — the 20% — that will bring the...
Read more >Profit Over People: The Commercial Bail Industry Fueling ...
Commercial bail industry decision-making processes prioritize profit over public safety. Because bail agents collect their premium based on ...
Read more >Texas bail legislation does little for poor people stuck in jail ...
Two priority bills this session would change the bail system, but they're primarily aimed at keeping potentially dangerous defendants behind ...
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
This is next on the list. It’s currently the last remaining item before we move to beta. It looks like your scenario is the same as @jsobell’s - you need rule prioritization within an ensure “bucket”. All rules in for the email property must be valid before allowing the
.satisfies(this.MayUseEmailAddress)
can be allowed to execute.Yes, I understand that, but that syntax suggests that the
.priority(100)
applies only to the email rule, so when someone adds.satisfiesRule('usernameUnique')
(assuming it will follow the emailUnique) it will actually be priority(0), so will execute with the lead rules.I’m suggesting that the priority number is irrelevant for anything other than ordered ‘grouping’, and that as such we can achieve an identical but more convention based approach by assigning the priority internally by simply using
.then()
as a group separator. The grouping order (i.e. priority) comes from the index of the.then
separated block’s. If we keep the idea of.priority(n)
but retain its state, we can also include a.then()
that is implemented as simply saying “this FluentEnsure.priority++”.This also brings in the issue of manual rules. At the moment I don’t see anything to specify that a rule only applies to manual validation (effectively saying priority(-1)) because we often have some rules that we only want executing on a full validate(). We can either say they have to be allocated in a new rule:
or we treat the fact that some rules are only used on full validation as being the lowest priority, and exclude them from partial validations.
If we did this by setting priority to -1 (for example) the validation resolver can ignore those rules on all but the full validate(), and we could have a syntax such as
This maintains the conventional order-based priorities, with the only restriction being that you can’t then use .priority or .then to append non-manual rules.
What do you think?