vfunc.js

Third-party integration

How to use existing libraries — maps, editors, charts, grids — in a vfunc app. There are four official adapters; for any other library, follow the steps below. From 1.0.0 the adapters ship in the vfunc package (vfunc/adapters/*).

Integration levels

LevelWhenResult
L0 direct useone screenthe vendor object created inside vf.vfunc({ onMount, onUpdate, onDestroy })
L1 app wrapperseveral screens of one appyour app's vfXxx(props) factory with the props it needs
L2 contract adapterswap engines by name, contribute itvf{Kind}{Vendor} that keeps the kind's contract and passes the contract tests

A Leaflet sample with the three levels side by side is in layer2/examples/third-party-custom/.

Official adapters

They keep the same contracts as the built-in vf.vfGrid and vf.vfChart, so switching is a change of name. The vendor library is not bundled: the app loads it first (pass it as lib or use its global).

AdapterFileVendor (checked version)LicenseIE11
vf.vfGridAgvfunc-grid-ag.jsAG Grid Community 36.2.0MITno
vf.vfGridTabulatorvfunc-grid-tabulator.jsTabulator 6.5.3MITno
vf.vfChartChartjsvfunc-chart-chartjs.jsChart.js 4.5.1MITno
vf.vfChartEchartsvfunc-chart-echarts.jsApache ECharts 6.1.0Apache-2.0no
<script src="https://cdn.jsdelivr.net/npm/echarts@6.1.0/dist/echarts.min.js"
        integrity="sha384-C2iskrW/uPW46KzOjrvJIQo4YkV8lkD+QS0CrDN18IIPIpT/g2USu8bTP3nvmIAD" crossorigin="anonymous"></script>
<script src="vfunc.min.js"></script>
<script src="vfunc-chart-echarts.min.js"></script>

Steps

The numbers match the TODO(n) comments of the adapter template layer2/adapters/_template/vfunc-kind-vendor.js.

  1. License: MIT, Apache-2.0, BSD and ISC can be used as they are. The GPL family affects how the app may ship. Revenue-based or commercial-only licenses are out. Add it to the app's NOTICE.
  2. Version and loading: from a CDN, an exact version with integrity (SRI) and crossorigin. The library from the lib prop, else its global. Wait for asynchronous loading.
  3. Host element: mark the element the vendor draws in with data-vf-keep. Never mix vendor DOM into render output.
  4. Create in onMount, from props turned into vendor options.
  5. Update: methods such as setData call the vendor's update API; do not create it again.
  6. Events: vendor events go to props callbacks as { sender, event, data }.
  7. Destroy in onDestroy: the vendor's destroy, and every listener, observer, subscription and timer you added.
  8. Size: ResizeObserver (else window resize) calls the vendor's resize.
  9. Theme: read the --vf-* tokens and pass them as the vendor's colors and fonts; no color values in JS.
  10. Locale: vf.i18n.subscribe changes the vendor's locale.
  11. XSS: where the vendor takes HTML strings, give it vf.esc text or nodes built with vf.html.
  12. .instance: expose the vendor object; say its features are outside the contract.
  13. Browsers: state the vendor's support as it is.
  14. Check: pass the contract tests, make a sample page, and create and destroy it 100 times to look for leaks.

Common traps

Contract tests

Give the base, grid and chart suites in layer2/adapters/_contract/ a factory and functions that press the UI, and they check the contract. The base contract checks .instance, refresh, destroy (twice), lib injection, the callback shape, listeners and timers left after 100 create/destroy cycles, survival of a parent refresh, and no logged errors.

Bringing it in with AI

Give the prompt layer2/ai/en/prompt-integrate-third-party.md (Korean: layer2/ai/ko/…) the library name and exact version, its documentation link and the level you want: it writes the component or adapter, a sample page and the contract test setup by the steps above. Check the result with the contract tests.

Sharing adapters and questions

To share an adapter or an app wrapper you made, or to ask where an integration got stuck, use the Adapters category of Discussions. Publish yours as a separate package named vfunc-adapter-* and post it there, and we list it on this site. To propose an official adapter, discuss it there first and follow the steps in CONTRIBUTING.