question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule prioritization and bailing

See original GitHub issue

We 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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
jdanyowcommented, Sep 7, 2016

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.

1reaction
jsobellcommented, Sep 1, 2016

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:

.ensure('startDate')
    .required()
.ensure('startDate')
    .manual()
    .satisfiesRule('lastSecondExpensiveCheck') // runs in parallel with:
    .satisfiesRule('lastSecondOtherExpensiveCheck') // this one

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

.ensure('startDate')
    .required()
    .manual()
    .satisfiesRule('lastSecondExpensiveCheck') // runs in parallel with:
    .satisfiesRule('lastSecondOtherExpensiveCheck') // this one

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found