aboutsummaryrefslogtreecommitdiffstats
path: root/src/types
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-11-09 11:17:18 +0100
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-11-12 12:59:25 +0100
commit7a5ae8b897548eef9efbf900b42936f24f911cea (patch)
tree9e1df6d92ba7e9266669f77e9ba374c61b975776 /src/types
parentd3f8d83551799db061a558537bc89dcbfd522c21 (diff)
downloadsvg.js-7a5ae8b897548eef9efbf900b42936f24f911cea.tar.gz
svg.js-7a5ae8b897548eef9efbf900b42936f24f911cea.zip
adds `List` which does bring back `SVG.Set` in an elegant way (#645)
Diffstat (limited to 'src/types')
-rw-r--r--src/types/List.js38
-rw-r--r--src/types/set.js18
2 files changed, 38 insertions, 18 deletions
diff --git a/src/types/List.js b/src/types/List.js
new file mode 100644
index 0000000..f3c0e1e
--- /dev/null
+++ b/src/types/List.js
@@ -0,0 +1,38 @@
+import { extend } from '../utils/adopter.js'
+import { subClassArray } from './ArrayPolyfill.js'
+
+const List = subClassArray('List', Array, function (arr) {
+ this.length = 0
+ this.push(...arr)
+})
+
+export default List
+
+extend(List, {
+ each (cbOrName, ...args) {
+ if (typeof cbOrName === 'function') {
+ this.forEach((el) => { cbOrName.call(el, el) })
+ } else {
+ this.forEach((el) => {
+ el[cbOrName](...args)
+ })
+ }
+
+ return this
+ },
+
+ toArray () {
+ return Array.prototype.concat.apply([], this)
+ }
+})
+
+List.extend = function (methods) {
+ methods = methods.reduce((obj, name) => {
+ obj[name] = function (...attrs) {
+ return this.each(name, ...attrs)
+ }
+ return obj
+ }, {})
+
+ extend(List, methods)
+}
diff --git a/src/types/set.js b/src/types/set.js
deleted file mode 100644
index c755c2c..0000000
--- a/src/types/set.js
+++ /dev/null
@@ -1,18 +0,0 @@
-/* eslint no-unused-vars: "off" */
-class SVGSet extends Set {
- // constructor (arr) {
- // super(arr)
- // }
-
- each (cbOrName, ...args) {
- if (typeof cbOrName === 'function') {
- this.forEach((el) => { cbOrName.call(el, el) })
- } else {
- this.forEach((el) => {
- el[cbOrName](...args)
- })
- }
-
- return this
- }
-}