Created
May 5, 2017 20:18
-
-
Save canac/d083fe4ad8067e2057900eae6bee3305 to your computer and use it in GitHub Desktop.
MissionHub debugging helpers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(() => { | |
const ngInjector = angular.element(document.querySelector('*[ng-app]')).injector(); | |
window.injector = new Proxy({}, { | |
get(target, property, receiver) { | |
return ngInjector.get(property); | |
} | |
}); | |
})(); | |
function setBetaMode(betaMode) { | |
injector.$rootScope.$applyAsync(() => { | |
injector.$rootScope.betaMode = betaMode; | |
}); | |
} | |
function toaster(...args) { | |
injector.$rootScope.$applyAsync(() => { | |
injector.toaster.pop(...args); | |
}); | |
} | |
function accessToken() { | |
return injector.$http.defaults.headers.common.Authorization.slice(7); | |
} | |
async function load(url) { | |
const res = await fetch(`http://localhost:3001/apis/v4/${url}`, { | |
headers: { | |
'Authorization': `Bearer ${injector.get('state').v4AccessToken}` | |
} | |
}); | |
const json = await res.json(); | |
injector.get('JsonApiDataStore').store.sync(json); | |
} | |
function findOne(...findArgs) { | |
return injector.get('JsonApiDataStore').store.find(...findArgs); | |
} | |
function findAll(...findArgs) { | |
return injector.get('JsonApiDataStore').store.findAll(...findArgs); | |
} | |
function person() { | |
return injector.JsonApiDataStore.store.find('person', 518182042); | |
} | |
function organization() { | |
return injector.JsonApiDataStore.store.find('organization', 7298); | |
} | |
function group() { | |
return injector.JsonApiDataStore.store.find('group', 662); | |
} | |
function log(value) { | |
return Promise.resolve(value) | |
.then(val => { | |
console.log(val); | |
return val; | |
}) | |
.catch(err => { | |
console.error(err); | |
throw err; | |
}); | |
} | |
function t(...args) { | |
return injector.tFilter(...args); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment