Download the PHP package hhvm/xhp-js without Composer
On this page you can find all versions of the php package hhvm/xhp-js. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package xhp-js
Short Description Easily create JS controllers for XHP elements, and XHP wrappers for React elements
License
Homepage https://github.com/hhvm/xhp-js
Informations about the package xhp-js
XHP-JS
XHP-JS is a combination of Hack and Javascript libraries allowing you to easily call Javascript functions or create Javascript classes that from XHP components, and to pass these classes or references to the DOM nodes to other Javascript code.
For convenience, an interface to construct React components is also included.
A short overview is available at https://code.facebook.com/posts/858739974205250
Examples
A full example is available at https://github.com/hhvm/xhp-js-example
Calling a Javascript function
Creating a Javascript Object
Creating a React component
This functionality was based on an extremely old React version. The example has been removed.
Writing your JavaScript
We recommend writing your modules as CommonJS modules, and using Browserify.
Alternatively, you can create them as members of the window object.
XHP-JS looks for modules as members of the window object, and falls back to attempting to call 'require("ModuleName")' - this requires a require() function to be defined in the global scope.
For example:
This Hack code can be thought of as creating the following Javascript:
In turn, your JavaScript may look like:
Installation
We recommend installing XHP-JS with Composer (for the Hack code) and npm + Browserify for the Javascript code. Alternatively, you can include xhpjs.js or xhpjs.min.js directly to declare an XHPJS object in the global scope.
See https://github.com/hhvm/xhp-js-example for a full example.
License
XHP-JS is MIT-licensed.