createComputedCache
Free version of Store.createComputedCache.
function createComputedCache<
Context extends StoreObject<any>,
Result,
Record extends
StoreObjectRecordType<Context> = StoreObjectRecordType<Context>,
>(
name: string,
derive: (context: Context, record: Record) => Result | undefined,
isEqual?: (a: Record, b: Record) => boolean
): {
get(context: Context, id: IdOf<Record>): Result | undefined
}
Example
const myCache = createComputedCache(
'myCache',
(editor: Editor, shape: TLShape) => {
return editor.getSomethingExpensive(shape)
}
)
myCache.get(editor, shape.id)
Parameters
Name | Description |
---|---|
|
|
|
|
|
|
Returns
{
get(context: Context, id: IdOf<Record>): Result | undefined
}