UNPKG

framer-motion

Version:

A simple and powerful JavaScript animation library

25 lines (22 loc) 596 B
import { addUniqueItem, removeItem } from 'motion-utils'; import { compareByDepth } from './compare-by-depth.mjs'; class FlatTree { constructor() { this.children = []; this.isDirty = false; } add(child) { addUniqueItem(this.children, child); this.isDirty = true; } remove(child) { removeItem(this.children, child); this.isDirty = true; } forEach(callback) { this.isDirty && this.children.sort(compareByDepth); this.isDirty = false; this.children.forEach(callback); } } export { FlatTree };