src/github.com/getlantern/lantern-ui/app/js/services.js
// XXX use modelValidatorSrvc to validate update before accepting
XXX use modelValidatorSrvc to validate update before accepting
XXX use modelValidatorSrvc to validate update before accepting
function handleSync(msg) {
      var patch = msg.data;
      if (patch[0].path !== '' && _.isEmpty(model)) {
        return;
      }
      function updateModel() {
        var shouldUpdateInstanceStats = false;
        if (patch[0].path === '') {
            angular.copy(patch[0].value, model);
          } else {
            try {
                applyPatch(model, patch);
                for (var i=0; i<patch.length; i++) {
                    if (patch[i].path == "/instanceStats") {
                        shouldUpdateInstanceStats = true;
                        break;
                      }
                  }
                } catch (e) {
                  if (!(e instanceof PatchApplyError || e instanceof InvalidPatch)) throw e;
                  apiSrvc.exception({exception: e, patch: patch});
                }
            }
        }
        if (!$rootScope.validatedModel) {
            $rootScope.$apply(updateModel());
            $rootScope.validatedModel = true
        } else {
            updateModel();
        }
      }
function handleSync ( msg ) { var patch = msg . data ; if ( patch [ 0 ] . path !== '' && _ . isEmpty ( model ) ) { return ; } function updateModel ( ) { var shouldUpdateInstanceStats = false ; if ( patch [ 0 ] . path === '' ) { angular . copy ( patch [ 0 ] . value , model ) ; } else { try { applyPatch ( model , patch ) ; for ( var i = 0 ; i < patch . length ; i ++ ) { if ( patch [ i ] . path == "/instanceStats" ) { shouldUpdateInstanceStats = true ; break ; } } } catch ( e ) { if ( ! ( e instanceof PatchApplyError || e instanceof InvalidPatch ) ) throw e ; apiSrvc . exception ( { exception : e , patch : patch } ) ; } } } if ( ! $rootScope . validatedModel ) { $rootScope . $apply ( updateModel ( ) ) ; $rootScope . validatedModel = true } else { updateModel ( ) ; } }
XXX use modelValidatorSrvc to validate update before accepting
XXX use modelValidatorSrvc to validate update before accepting
// backend can send updates before model has been populated // https://github.com/getlantern/lantern/issues/587 //log.debug('ignoring', msg, 'while model has not yet been populated'); // XXX jsonpatch can't mutate root object https://github.com/dharmafly/jsonpatch.js/issues/10 //log.error('Error applying patch', patch);