import { BlockIDStr } from "./BlocksStore" ; import { action , computed , makeObservable , observable } from "mobx" ; export class ReverseIndex { @ observable private index : { [ key ] : BlockIDStr [ ] ; } = { } ; @ computed get ( target ) { return this . index [ target ] || [ ] ; } @ action add ( target , inbound ) { const current = this . index [ target ] ; if ( current ) { current . push ( inbound ) ; } else { this . index [ target ] = [ inbound ] ; } } @ action remove ( target , inbound ) { const current = this . index [ target ] ; if ( current ) { const idx = current . indexOf ( inbound ) ; if ( idx > - 1 ) { current . splice ( idx , 1 ) ; } if ( current . length === 0 ) { delete this . index [ target ] ; } } } }