-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.php
86 lines (76 loc) · 1.89 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?hh
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
require_once(__DIR__.'/vendor/autoload.php');
class :test extends :x:element {
use XHPHelpers;
use XHPJSCall;
use XHPJSInstance;
attribute :xhp:html-element;
protected function render(): XHPRoot {
/* Roughly equivalent to:
*
* var MyJSModule = require('MyJSModule');
* MyJSModule.myJSFunction(
* 'hello, world',
* <result of constructJSInstance() call below>
* );
*
* The JS code realizes it needs to construct the JS class first, despite
* the call below.
*/
$this->jsCall(
'MyJSModule',
'myJSFunction',
'hello, world.',
XHPJS::Instance($this)
);
/*
* var MyJSController = require('MyJSController');
* new MyJSController(
* document.getElementById(< $this->getID() >);
* 'herp derp'
* );
*/
$this->constructJSInstance(
'MyJSController',
XHPJS::Element($this),
'herp derp',
);
return <div id={$this->getID()}>In :test::render()</div>;
}
}
class :react-test extends :x:element {
use XHPHelpers;
use XHPReact;
attribute
:xhp:html-element,
string some-attribute @required;
protected function render(): XHPRoot {
// Self-explanatory :)
$this->constructReactInstance(
'MyReactClass',
Map {'someAttribute' => $this->:some-attribute }
);
return <div id={$this->getID()} />;
}
}
$xhp =
<html>
<head>
<script src="build/bundle.js" />
</head>
<body>
<x:js-scope>
<test />
<react-test some-attribute="some value" />
</x:js-scope>
</body>
</html>;
print $xhp;