https://github.com/featurist/hyperdom-sortable
sortable lists for hyperdom
https://github.com/featurist/hyperdom-sortable
Last synced: about 2 months ago
JSON representation
sortable lists for hyperdom
- Host: GitHub
- URL: https://github.com/featurist/hyperdom-sortable
- Owner: featurist
- Created: 2015-07-15T08:04:43.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-12-06T17:04:38.000Z (over 8 years ago)
- Last Synced: 2025-02-24T15:44:30.693Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# hyperdom-sortable
Sortable lists for hyperdom.
## example
```js
var hyperdom = require('hyperdom');
var h = hyperdom.html;
var sortable = require('hyperdom-sortable');function render(model) {
return sortable('li', model.items, function (item) {
return h('li', item);
});
}hyperdom.append(document.body, render, {items: [
'red',
'blue',
'yellow'
]});
```## api
```js
var sortable = require('hyperdom-sortable');var vdom = sortable(selector, [options], list, mapFunction);
```* `selector` - the selector to be passed to `hyperdom.html`, i.e. `'li'`.
* `options` - the options to be passed to `hyperdom.html`
* `options.moveItem(fromIndex, toIndex)` - optional, called to move the item in `list` from `fromIndex` to `toIndex`. If not provided, the item is moved in `item`.
* `options.onitemmoved(item, fromIndex, toIndex)` - called after an item in the list was moved.
* `list` - the list of items from the model. Items in this list will be moved when the user sorts the list.
* `mapFunction(item)` - a function taking an item from `list`, and producing the corresponding vdom.