UNPKG

substance

Version:

Substance is a JavaScript library for web-based content editing. It provides building blocks for realizing custom text editors and web-based publishing system. It is developed to power our online editing platform [Substance](http://substance.io).

35 lines (30 loc) 664 B
import deleteFromArray from './deleteFromArray' import getKeyForPath from './getKeyForPath' import isString from './isString' // simplified version of TreeIndex for arrays export default class ArrayTree { add (path, val) { const key = this._getKey(path) if (!this[key]) { this[key] = [] } this[key].push(val) } remove (path, val) { const key = this._getKey(path) if (this[key]) { deleteFromArray(this[key], val) } } get (path) { const key = this._getKey(path) return this[key] || [] } _getKey (path) { if (isString) { return path } else { return getKeyForPath(path) } } }