Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit e0d3e83

Browse files
Tom Hardinggaryb
authored andcommitted
Add toArray for HTMLCollection (#109)
* Add `toArray` for HTMLCollection With a lot of help from @garyb, here's the `toArray` for HTMLCollection. It returns the elements within the collection as an Array of Element objects. It was suggested that this be returned as an Unfoldable, but the `item` function is effectful, so the plan was ruined. * Update toArray to use FFI It's not great, but it's going to be more performant and just as "correct" (for some definition of correctness).
1 parent 2bea9c7 commit e0d3e83

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/DOM/Node/HTMLCollection.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ exports.length = function (list) {
66
};
77
};
88

9+
exports.toArray = function (list) {
10+
return function () {
11+
return [].slice.call(list);
12+
};
13+
};
14+
915
exports._item = function (index) {
1016
return function (list) {
1117
return function () {

src/DOM/Node/HTMLCollection.purs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import DOM.Node.Types (Element, HTMLCollection, ElementId)
1414
-- | The number of elements in a HTMLCollection.
1515
foreign import length :: forall eff. HTMLCollection -> Eff (dom :: DOM | eff) Int
1616

17+
-- | The elements of an HTMLCollection represented in an array.
18+
foreign import toArray :: forall eff. HTMLCollection -> Eff (dom :: DOM | eff) (Array Element)
19+
1720
-- | The element in a HTMLCollection at the specified index, or Nothing if no such
1821
-- | element exists.
1922
item :: forall eff. Int -> HTMLCollection -> Eff (dom :: DOM | eff) (Maybe Element)

0 commit comments

Comments
 (0)