summaryrefslogtreecommitdiff
path: root/src/array.js
diff options
context:
space:
mode:
authorAnthony Wang2023-02-15 16:22:43 -0500
committerAnthony Wang2023-02-15 16:22:43 -0500
commit091ff04c2420c8549ff581399212b4e3346864ee (patch)
tree746ad8767db3f3eab288eab4f08b74c37742777e /src/array.js
parentfb3c976380e704a1c129f141f0bdb7f5f4576611 (diff)
Delete all files except for demo
Diffstat (limited to 'src/array.js')
-rw-r--r--src/array.js61
1 files changed, 0 insertions, 61 deletions
diff --git a/src/array.js b/src/array.js
deleted file mode 100644
index ae30012..0000000
--- a/src/array.js
+++ /dev/null
@@ -1,61 +0,0 @@
-// Extend the array class to expose update
-// functionality, plus provide some
-// useful helper methods
-export default function(graffiti) {
-
- return class GraffitiArray extends Array {
-
- get mine() {
- return this.filter(o=> o._by==graffiti.myID)
- }
-
- get notMine() {
- return this.filter(o=> o._by!=graffiti.myID)
- }
-
- get authors() {
- return [...new Set(this.map(o=> o._by))]
- }
-
- removeMine() {
- this.mine.map(o=> delete o._key)
- }
-
- #getProperty(obj, propertyPath) {
- // Split it up by periods
- propertyPath = propertyPath.match(/([^\.]+)/g)
- // Traverse down the path tree
- for (const property of propertyPath) {
- obj = obj[property]
- }
- return obj
- }
-
- sortBy(propertyPath) {
-
- const sortOrder = propertyPath[0] == '-'? -1 : 1
- if (sortOrder < 0) propertyPath = propertyPath.substring(1)
-
- return this.sort((a, b)=> {
- const propertyA = this.#getProperty(a, propertyPath)
- const propertyB = this.#getProperty(b, propertyPath)
- return sortOrder * (
- propertyA < propertyB? -1 :
- propertyA > propertyB? 1 : 0 )
- })
- }
-
- groupBy(propertyPath) {
- return this.reduce((chain, obj)=> {
- const property = this.#getProperty(obj, propertyPath)
- if (property in chain) {
- chain[property].push(obj)
- } else {
- chain[property] = new GraffitiArray(obj)
- }
- return chain
- }, {})
- }
-
- }
-}