oakes / odoyle-rules

A rules engine for Clojure(Script)
The Unlicense
530 stars 20 forks source link

How to remove a rule dynamically? #26

Closed ertugrulcetin closed 11 months ago

ertugrulcetin commented 12 months ago

I'd like to remove a rule dynamically, is it possible in current API, if not do you have quick code snippet?

ertugrulcetin commented 12 months ago

@oakes any ideas?

oakes commented 12 months ago

There is no support for removing rules right now. I think it would be fairly straight-forward to implement, but what is your use case? Are you adding/removing rules dynamically?

nivekuil commented 12 months ago

I would use this to write a react hook that subscribes to an odoyle session, so o/add-rule on mount and then remove the rule on unmount.

ertugrulcetin commented 12 months ago

@oakes when I'm writing or updating rules in my ClojureScript project, Shadow-cljs hot-loads the rules with each file change. Thus, I need to remove rules before each hot load. Additionally, I can manipulate them while working in my REPL. So, it's crucial for my use case. Also yes, I'm adding/removing rules dynamically

oakes commented 12 months ago

@nivekuil @ertugrulcetin Can you please try the latest commit? I added remove-rule which works like this:

(o/remove-rule session ::my-rule-name)

If you're using deps.edn you can bring the commit in like this:

net.sekao/odoyle-rules {:git/url "https://github.com/oakes/odoyle-rules.git"
                        :git/sha "800aba8053a1643184ca395a6712d1e1d34e973a"}
ertugrulcetin commented 12 months ago

@oakes, thank you so much for the update! It seems to be working for me. I initially thought it would be harder to remove given the presence of defrecords and the complex logic during node construction. I assumed it would require more steps to remove a rule, similar to maintaining balance in a tree

oakes commented 12 months ago

I thought it'd be harder too :P It would've been if there was any node-sharing going on, but I never implemented that because I thought it would complicate the codebase.

ertugrulcetin commented 12 months ago

Cool, thanks again! I think you can push the new release to clojars

oakes commented 11 months ago

On second thought, I think there is a bit more I need to do to properly remove the rule. I will look into this today.

ertugrulcetin commented 11 months ago

@oakes okay thanks a lot! Also could you check this new issue once you have time? It is very important IMHO: https://github.com/oakes/odoyle-rules/issues/27

oakes commented 11 months ago

Yep sure I'll take a look later today.

oakes commented 11 months ago

This feature is now in version 1.3.0, so I'll close this.

ertugrulcetin commented 11 months ago

@oakes Thank you for the update, I appreciate it!