ForesightJS v4.0 - Official Framework Packages #118
spaansba
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The goal of v4.0 is to make ForesightJS a lot easier to use with popular frameworks. Until now, the docs handed you premade hooks, composables and directives to copy into your own project. v4 replaces all of that with two official wrapper packages:
@foresightjs/reactand@foresightjs/vue. Install one, delete your copied files, and you're done.To make reactive bindings possible, the core element data model was reworked into immutable state snapshots with a subscription model. The same primitives the wrapper packages are built on, and the same ones you can use to build a binding for your own framework (Angular, Svelte, Solid, …).
Upgrading from v3.5? Follow the migration guide. The v3.5 docs stay available via the version dropdown.
js.foresightv4.0.0ForesightElementDatais nowForesightElementState: a flat, immutable snapshot whose reference is replaced (never mutated) on every change, so it plugs straight into any reactivity system.register()return value. Besides the element state it now returnsunregister,subscribeandgetSnapshotisTouchDeviceis gone from the result; touch devices are handled internally by thetouchDeviceStrategyglobal setting.updateElementOptions(). Change the options of an already-registered element in place. See registration options.enabledelement option. Keep an element registered but excluded from prediction.unregisters it; it's parked (
isParked: true) and resumes automatically when it reconnects.elementDataUpdated,elementOptionsUpdatedandelementReactivatedevents are removed in favor of the subscriber pattern; the remaining events carry the snapshot in astatefield.debugglobal setting (usejs.foresight-devtools) andunregisterOnCallback(usereactivateAfter) are gone.isConnectedguards.Devtools —
js.foresight-devtoolsv2.0.0showoptions to toggle each visualization individually:controlPanel,nameTags,elementOverlays,mouseTrajectoryandscrollTrajectory.inactive elements carry reason badges (
disabled,parked,limited,fired) explaining why.New —
@foresightjs/reactOfficial React (18+) bindings, with dedicated React docs including Next.js and [React Router (https://foresightjs.com/docs/react/react-router) guides.
useForesight— register a single element and getits live state plus a callback ref to bind it.
useForesights— register a dynamic list ofelements from one hook call.
useForesightEvent— subscribe to aForesightManager event for the lifetime of the component.
hitSlopandenabledare reactive — change a prop and the registration updates.New —
@foresightjs/vueOfficial Vue 3 (3.5+) bindings, with [dedicated Vue docs (https://foresightjs.com/docs/vue/installation).
v-foresight— directive to register an element with a callback or full options object.useForesight— register a single element and get reactive refs for its state.useForesights— register a dynamic list of elements from a single composable.useForesightEvent— subscribe to a ForesightManager event for the lifetime of the calling scope.Docs
subscribe/getSnapshotpattern (Angular, Svelte, Solid examples). If you build one, sharing it is highly appreciated!This discussion was created from the release ForesightJS v4.0 - Official Framework Packages.
Beta Was this translation helpful? Give feedback.
All reactions