BREAKING CHANGES: - lib/modules!: Renamed `callBridgeMethod*` to `callNativeMethod*` and interface `Methods` to `NativeMethods`. This is to achieve naming consistency with the native API and be more clear. - lib/storage!: Renamed to `@revenge-mod/json-storage`. A storage can be in any arbitrary format. While there's little potential for non-JSON storage formats, but the naming should allow for it regardless. This is not a drop-in replacements. There are breaking changes in export names and new APIs. - plugins/revenge.api.storage!: Renamed to `revenge.api.jsonStorage`. Plugin options are renamed and its structure has changed as well. - Native now holds the path for official storage APIs. This update uses new paths without any migration! - lib/plugins!: `Plugin.errors` is now read-only. Use `Plugin.reportError(e)` instead. - lib/plugins!: `Plugin.flags` has been completely removed in favor of these methods: `Plugin.requireReload()`, `Plugin.disable()`. OTHER CHANGES: - Fixed sorting for 'Enabled first' - Updated native method names to be more consistent - Cleand up dead code - Make methods more 'safe' by removing non-null assertion casts
24 lines
722 B
TypeScript
24 lines
722 B
TypeScript
import { JsonStorage } from '@revenge-mod/json-storage'
|
|
import { useReRender } from '@revenge-mod/utils/react'
|
|
import { useLayoutEffect } from 'react'
|
|
import type { JsonStorageSubscription } from '@revenge-mod/json-storage'
|
|
|
|
const proto = JsonStorage.prototype as JsonStorage<any>
|
|
// Actual implementation of JsonStorage#use
|
|
proto.use = function (filter) {
|
|
if (!this.cache) this.get()
|
|
|
|
const reRender = useReRender()
|
|
|
|
useLayoutEffect(() => {
|
|
const sub: JsonStorageSubscription = filter
|
|
? (update, mode) => {
|
|
if (filter(update, mode)) reRender()
|
|
}
|
|
: reRender
|
|
|
|
return this.subscribe(sub)
|
|
}, [filter, reRender])
|
|
|
|
return this.cache
|
|
}
|