-
Notifications
You must be signed in to change notification settings - Fork 42
Tracking: sortable API #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
…rs much easier (~50 LOC of boilerplate saved in the Kanban example, as predicted in #69)
Choices left to make
Todos
|
@Digister beta is out. Moved to scoped packages too. |
So I didn't think I was interested in this, because, at the moment, I'm pretty happy with the simple sortable directive I made on top of angular-skyhook, but your use cases blurb in the docs is compelling. I'm refactoring my apps backend at the moment, but I'll check this out in a few weeks. Thanks! 👍 |
@thefliik Glad to hear it! When you do, let me know if there are any ways you think it could improve! (You should also know that this is just one big 'basic sortable' under the hood, but easier, more powerful and requiring less plumbing. Ideally refactoring to use it should involve deleting a bunch of code, mainly that huge 'hover' function.) |
Uh oh!
There was an error while loading. Please reload this page.
This is a tracking issue for the sortable functionality.
It won’t be part of the core package, it will be separate. At this stage I’m looking for feedback and comments on API design. Please 👍🏻 if you want to beta test the basic directive/component stuff.
What is it at the moment?
The best intro to the WIP functionality is reading the Kanban example source code. A quick rundown:
angular-skyhook-card-list
, but this name is bad[cardRenderer]="cardList.contextFor(data, index)"
source
to the DOMSortableSpec
The main factor to consider in decision-making is that implementing SortableSpec according to the needs of the library as it exists now is difficult. The library is fundamentally more flexible than the alternatives which all do at least some array work themselves (ex. Ng2-Dragula, 100% of it; Cdk-experimental, apparently the hover states are handled).
It probably isn't possible to handle all the hover states internally / simplify the spec to just confirmed moves. How would you do that while supporting arbitrary ngFor/deep children/some elements fixed? The relevant CDK code excludes some of these possibilities in its internal implementation — it just runs insertBefore with some prerendered Dom.
SortableSpec requires, currently:
{ [k: string]: Data[] }
or at least a list of lists (like the Kanban example)2 means simple array mutations are out, and slice(0) is in. 6 is a hurdle because few people in the wild are comfortable enough with Rx to do this on their own. Nevertheless, every item can be tricky if you attack the problem blindly.
Copy/clone support
Should SortableSpec include copy/clone functionality? Currently those features appear to require internal support from the directives due to Chrome bugs. Needs a second look.
If you add copy/clone, there are actually three more requirements for SortableSpec implementations:
SortableSpec implementation strategies
There are two main strategies I’ve used so far.
Direct (not very good)
hover() { current = move(beforeDrag, ...) }
drop() { beforeDrag = move(beforeDrag, ...); }
Pros: no NgRx needed.
Cons: much more complicated to write, and difficult to get bug-free, especially when supporting externals and clones. Half of the moveCard function is in an if block.
Just-In-Time
Similar to react-sortable-tree. See Kanban again.
Pros: Simple hover implementation that just updates the item to be inserted later. Simple handling of externals and clones; just don’t delete the original and proceed as usual.
Cons: kinda need NgRx and all that baggage.
(Side note: could you do step 3 of JIT without requiring users to implement it themselves? Probably not. We want to support Immutable.js, for example, which doesn't have the same insert API as arrays.)
Shipping SortableSpec implementations?
As far as I can see, there are no satisfactory reasons for actually shipping any complex SortableSpec implementations. Any such implementation would need to be complete, dependency-free (manual immutables, no NgRx), and configurable (how? The directives I wrote to do this are really bad, and there’s no easy way to make a spec that updates a component variable without weird callbacks or subscriptions.). That would be a maintenance nightmare, and because the code would look really scary (see: the other requirements), users would make feature requests instead of building features themselves.
I also really don’t want people using whatever spec that’s available as an alternate data store. Sortable should work with your existing data. The Kanban example store is great because it takes existing data and builds a spec that simply interacts with that, and you have complete control.
On the other hand, people don't typically want to use more than one dnd library, as it has a cost on bundle size. There is a mid-point between extensibility and ease of use that might not be covered without any shipping specs that are easy to use.
SharedSortableSpec -- potential
The most promising spec to ship would be the ng2-dragula replacement, SharedSortableSpec. It would probably be rewritten to resemble a mini-NgRx with the JIT strategy, and the directive that applies it would be subsumed within CardListDirective so it wouldn't be nearly as hacky.
Pros: worthy replacement for ng2-dragula and approximately as simple as all the other solutions out there.
Cons: maintenance, non-extensibility, and feature creep. Basically, all the reasons why you wouldn't use other libraries. Because it's easier than using ngrx, people would choose it as the default, and wouldn't be able to add features.
NgRX helpers (edit: DONE)
I have one last idea for what to ship:
This would remove about 50 lines of boilerplate from the kanban demo. More importantly, it would represent a focus on advanced NgRx-based use cases and not simple one-component lists, for which there are abundant easier alternatives.
The text was updated successfully, but these errors were encountered: