lib/observable/subscribe/index.js
function subscribe (obs, path, index, length, type, val, id, fire, origin, event, nocontext) {
  if (index === length) {
    // TODO added this to subscribe to key => this is probably not the best way to catch this
    if (obs.on) {
      obs.on('remove', function () {
        // null
        subscribe(origin, path, 0, length, type, val, id, false, origin, event)
      }, id, true, event, nocontext)
      obs.on(type, val, id, true, event, nocontext)
    }
    if (fire) {
      // **TODO** SUPER DIRTY
      // need to have some godamn arguments
      if (event === void 0) {
        var trigger = true
        event = new Event('data') // wrong
      }

      if (typeof val === 'function') {
        val.call(obs, obs.__input, event)
      } else {
        // weird gaurd
        if (val && val[0]) {
          val[0].call(obs, type === 'data' ? obs.__input : void 0, event, val[1])
        }
      }

      if (trigger) {
        event.trigger()
      }
    }
    return obs
  } else {
    let key = path[index]
    let property = obs[key]
    let result

    if (property && property.__input !== null) {
      result = subscribe(property, path, index + 1, length, type, val, id, fire, origin, event, nocontext)
    } else {
      let listenerType = key === 'parent' ? key : 'property'
      let listener = function (data, event) {
        let property = obs[key]
        if (property) {
          obs.off(listenerType, id, void 0, true)
          subscribe(property, path, index + 1, length, type, val, id, true, origin, event, nocontext)
        }
      }
      obs.on(listenerType, listener, id, true, event, nocontext)
    }

    // if sub is not fulfilled look in the reference
    if (!result) {
      let reference = ref(obs)
      if (reference) {
        subscribe(reference, path, index, length, type, val, id, fire, origin, event, nocontext)
      }
    }
  }
}
function subscribe (obs, path, index, length, type, val, id, fire, origin, event, nocontext) {
  if (index === length) {
    // TODO added this to subscribe to key => this is probably not the best way to catch this
    if (obs.on) {
      obs.on('remove', function () {
        // null
        subscribe(origin, path, 0, length, type, val, id, false, origin, event)
      }, id, true, event, nocontext)
      obs.on(type, val, id, true, event, nocontext)
    }
    if (fire) {
      // **TODO** SUPER DIRTY
      // need to have some godamn arguments
      if (event === void 0) {
        var trigger = true
        event = new Event('data') // wrong
      }

      if (typeof val === 'function') {
        val.call(obs, obs.__input, event)
      } else {
        // weird gaurd
        if (val && val[0]) {
          val[0].call(obs, type === 'data' ? obs.__input : void 0, event, val[1])
        }
      }

      if (trigger) {
        event.trigger()
      }
    }
    return obs
  } else {
    let key = path[index]
    let property = obs[key]
    let result

    if (property && property.__input !== null) {
      result = subscribe(property, path, index + 1, length, type, val, id, fire, origin, event, nocontext)
    } else {
      let listenerType = key === 'parent' ? key : 'property'
      let listener = function (data, event) {
        let property = obs[key]
        if (property) {
          obs.off(listenerType, id, void 0, true)
          subscribe(property, path, index + 1, length, type, val, id, true, origin, event, nocontext)
        }
      }
      obs.on(listenerType, listener, id, true, event, nocontext)
    }

    // if sub is not fulfilled look in the reference
    if (!result) {
      let reference = ref(obs)
      if (reference) {
        subscribe(reference, path, index, length, type, val, id, fire, origin, event, nocontext)
      }
    }
  }
}
function subscribe ( obs , path , index , length , type , val , id , fire , origin , event , nocontext ) { if ( index === length ) { // TODO added this to subscribe to key => this is probably not the best way to catch this if ( obs . on ) { obs . on ( 'remove' , function ( ) { // null subscribe ( origin , path , 0 , length , type , val , id , false , origin , event ) } , id , true , event , nocontext ) obs . on ( type , val , id , true , event , nocontext ) } if ( fire ) { // **TODO** SUPER DIRTY // need to have some godamn arguments if ( event === void 0 ) { var trigger = true event = new Event ( 'data' ) // wrong } if ( typeof val === 'function' ) { val . call ( obs , obs . __input , event ) } else { // weird gaurd if ( val && val [ 0 ] ) { val [ 0 ] . call ( obs , type === 'data' ? obs . __input : void 0 , event , val [ 1 ] ) } } if ( trigger ) { event . trigger ( ) } } return obs } else { let key = path [ index ] let property = obs [ key ] let result if ( property && property . __input !== null ) { result = subscribe ( property , path , index + 1 , length , type , val , id , fire , origin , event , nocontext ) } else { let listenerType = key === 'parent' ? key : 'property' let listener = function ( data , event ) { let property = obs [ key ] if ( property ) { obs . off ( listenerType , id , void 0 , true ) subscribe ( property , path , index + 1 , length , type , val , id , true , origin , event , nocontext ) } } obs . on ( listenerType , listener , id , true , event , nocontext ) } // if sub is not fulfilled look in the reference if ( ! result ) { let reference = ref ( obs ) if ( reference ) { subscribe ( reference , path , index , length , type , val , id , fire , origin , event , nocontext ) } } } }
subscriptions have to take care of references we have to add walking over the refs here
subscriptions have to take care of references we have to add walking over the refs here