0.1.0 • Published 1 year ago

@bablr/weak-stack v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@bablr/weak-stack

An immutable stack implementation which uses weakMaps to track frames. Usage is slightly easier than a something like @iter-tools/imm-stack because the frame with the data is the stack reference you hold.

Usage

import { WeakStackFrame } from '@bablr/weak-stack';

class Path extends WeakStackFrame {
  constructor(reference, coverType) {
    this.reference = reference;
    this.coverType = coverType;
  }
}

let s = {
  path: Path.create('root', 'Fragment'),
};

assert(s.path.coverType === 'Fragment');

s.path = s.path.push('children', 'Expression');

assert(s.path.coverType === 'Expression');

s.path = s.path.pop();

assert(s.path.coverType === 'Fragment');