sorted todomvc using js/Date#5
sorted todomvc using js/Date#5usernolan wants to merge 1 commit intoCoNarrative:masterfrom usernolan:todomvc-sort
Conversation
|
This was a pretty simple approach. I can't tell if there are any trade offs between sorting in context (like this solution) and sorting in the rule that produces visible-todos. Do you think it would be easier to implement a "sort" enum like the visibility-filter i.e. hold a sort-enum fact and conditionally sort in the rule? |
|
I think that's a great way to do it actually. I've been relatively dogmatic about doing everything with rules and I think this shows that's not always necessary. Thanks for sharing this. The rules engine should be able to produce a sorted list though. For this case I think the best solution is a custom accumulator. This will produce a list that we (currently) can't pattern match on, but it could be output for public consumption and still be useful. The accumulators namespace shows a couple efforts to make custom accumulator functions. Clara has designed a great interface for this. We should be able to maintain and return a list of facts and return it, and provide parameters to define what to sort by (value usually) and what to return. Note we can't currently pass bound variables (anything with The approach with visible todos was to get accumulate all eids of todos that are visible and then pass that list of eids to Here's somewhat of a hybrid approach we took in the fullstack example that prevents the view from having to perform or know about sort logic: https://github.com/CoNarrative/precept/blob/master/examples/fullstack/src/cljs/fullstack/rules.cljs#L137 |
|
That definitely seems like a better, less naive solution. I think the sort order should be decoupled from the views (although leaving this as an option isn't a bad thing), and rather provide a parameterized accumulator like you mention/directly expose the expressiveness in Clara. I haven't been able to work much with accumulators--if you want to give me a 30 sec intro to repl'ing with them, I'd be happy to PR some examples to the docs to lower that specific barrier of entry. The reason this might be helpful is that, while Precept relieves the pain point of structuring and restructuring state in traditional Redux/re-frame (which is a huge strength), it's important to understand how accumulating the view of the world in a particular shape (e.g. sort) should be done. Even if the one-off solutions will always exist (and probably even be pretty ok, like this little 3 line change, given its clj/s). Anyway, sorry to continue bothering you on the todomvc example! It's been great getting experience with the framework. |
Naive implementation of sorting the todos.