Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// fetch: fetcher,
alert: m => console.log(m) // Noop for demo: window.alert(m)
}
)
}
if(store === null) {
store = Store.create(
{},
{
// fetch: fetcher,
alert: m => console.log(m) // Noop for demo: window.alert(m)
}
)
}
if (snapshot) {
applySnapshot(store, snapshot)
}
return store
}
export const safeApplySnapshot = (target: IStateTreeNode, snapshot: any) => {
try {
applySnapshot(target, snapshot)
return true
} catch (e) {
// tslint:disable-next-line:no-console
console.error(e)
alert(
"Saved outline was found to be corrupt." +
"Please report this as an issue." +
"It will help us debug if you could also attach the downloaded snapshot in the bug report"
)
try {
downloadJSON(snapshot)
} catch (e) {
// tslint:disable-next-line:no-console
console.error(e)
alert("Failed to download snapshot")
}
load: flow(function*() {
const data = yield load(key)
if (data) {
applySnapshot(self, data)
}
// now monitor for changes
if (autoSave) {
enableSaving()
}
// send back the data
return data
}) as () => Promise,
(async () => {
Account.setIsChecking(true);
try {
const data = JSON.parse(await AsyncStorage.getItem('Account'));
applySnapshot(Account.read, data.read);
applySnapshot(Account.voted, data.voted);
applySnapshot(Account.favorited, data.favorited);
applySnapshot(Account.flagged, data.flagged);
applySnapshot(Account.hidden, data.hidden);
} catch (err) {
console.log('Could not decode Account');
}
let username;
let password;
try {
const credentials = await Keychain.getInternetCredentials('news.ycombinator.com');
if (credentials) {
username = credentials.username;
password = credentials.password;
} else {
Account.setIsChecking(false);
return false;
}
(async () => {
Account.setIsChecking(true);
try {
const data = JSON.parse(await AsyncStorage.getItem('Account'));
applySnapshot(Account.read, data.read);
applySnapshot(Account.voted, data.voted);
applySnapshot(Account.favorited, data.favorited);
applySnapshot(Account.flagged, data.flagged);
applySnapshot(Account.hidden, data.hidden);
} catch (err) {
console.log('Could not decode Account');
}
let username;
let password;
try {
const credentials = await Keychain.getInternetCredentials('news.ycombinator.com');
if (credentials) {
username = credentials.username;
password = credentials.password;
} else {
isServer: boolean,
snapshot = null
): ModelCreationType {
if (isServer) {
store = RootStore.create(undefined, {
gqlHttpClient: createHttpClient("http://localhost:3000/api/graphql"),
ssr: true
})
}
if (store === null) {
store = RootStore.create(undefined, {
gqlHttpClient: createHttpClient("http://localhost:3000/api/graphql")
})
}
if (snapshot) {
applySnapshot(store, snapshot)
}
return store
}
export function getStore(snapshot = null): ModelCreationType {
if (isServer || !store) {
store = RootStore.create(undefined, {
gqlHttpClient: createHttpClient("http://localhost:3000/api/graphql"),
ssr: true
})
}
if (snapshot) {
applySnapshot(store, snapshot)
}
return store
}
_loadPersistedState = async () => {
const retrievedState = await AsyncStorage.getItem(appStatePersistenceKey);
if (retrievedState) {
const rootStoreJson = JSON.parse(retrievedState);
if (RootStore.is(rootStoreJson)) {
applySnapshot(this.rootStore, rootStoreJson);
}
}
};
const allBoxes = values(store.boxes)
for (let i = 0; i < amount; i++) {
store.addArrow(
allBoxes[Math.floor(Math.random() * allBoxes.length)],
allBoxes[Math.floor(Math.random() * allBoxes.length)]
)
}
})
}
/**
Save / Restore the state of the store while self module is hot reloaded
*/
if (module.hot) {
if (module.hot.data && module.hot.data.store) {
applySnapshot(store, module.hot.data.store)
}
module.hot.dispose(data => {
data.store = getSnapshot(store)
})
}
function initStore (
isServer,
snapshot = null,
panoptesClient = defaultClient,
) {
if (isServer) {
store = Store.create({}, { panoptesClient })
}
if (store === null) {
store = Store.create({}, { panoptesClient })
}
if (snapshot) {
applySnapshot(store, snapshot)
}
return store
}