Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getBlocksSync = () => {
// May return synchronously, or may throw with either an actual error or a
// loading promise. We should never see a Promise thrown as .serialize()
// only gets called during event handlers on the client _after_ all the
// React Suspense calls are fully resolved. We want the
// returns-synchronously case. Otherwise, we want to either rethrow any
// error thrown, or throw a new error indicating an unexpected Promise was
// thrown.
try {
return this.getBlocks();
} catch (loadingPromiseOrError) {
if (isPromise(loadingPromiseOrError)) {
// `.getBlocks()` thinks it's in React Suspense mode, which we can't
// handle here, so we throw a new error.
throw new Error(
'`Content#getBlocks()` threw a Promise. This may occur when calling `Content#(de)serialize()` before blocks have had a chance to fully load.'
);
}
// An actual error occurred
throw loadingPromiseOrError;
}
};
.map(executor => {
try {
values.push(executor());
} catch (loadingPromiseOrError) {
// An actual error was thrown, so we want to bubble that up
if (!isPromise(loadingPromiseOrError)) {
throw loadingPromiseOrError;
}
// Return a Suspense promise
return loadingPromiseOrError;
}
})
.filter(Boolean);
const getPromiseFromKey = (values, key) =>
isPromise(values[key]) ? handler(values[key])(key) : values[key](key)
const clonedObj = cloneDeep(obj)
const safeObj = prefixConflictingKeys(clonedObj)
let node = {
...safeObj,
id: generateNodeId(type, obj.id),
parent: sourceId,
children: [],
internal: {
type: generateTypeName(type),
},
}
node = middleware(node)
if (isPromise(node))
return node.then(resolvedNode =>
withDigest({
...resolvedNode,
...overrides,
}),
)
return withDigest({
...node,
...overrides,
})
}