import { observable , action , computed } from 'mobx' ; export class EmptyStackError extends Error { } /**
 * Array backed generic stack store
 */ export default class ListStore < T > { @ observable data : T [ ] = [ ] ; private assertDataHasElements ( ) { if ( this . data . length < 1 ) { throw new EmptyStackError ( 'Can not peek/pop an element off of an empty stack!' ) ; } } @ action . bound push ( element ) { this . data . push ( element ) ; } @ action . bound pop ( ) { this . assertDataHasElements ( ) ; return this . data . pop ( ) ! ; } @ action . bound removeIndex ( index ) { this . data = observable . array ( [ ... this . data . slice ( 0 , index ) , ... this . data . slice ( index + 1 ) ] ) ; } @ computed get peek ( ) : T { this . assertDataHasElements ( ) ; return this . data [ 0 ] ; } @ computed get doesHaveElements ( ) : boolean { return this . data . length > 0 ; } }