-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathREADME.html
177 lines (134 loc) · 5.77 KB
/
README.html
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<h1>Jint.Ex - Alpha</h1>
<h2>Overview</h2>
<p>The Jint.Ex framework extends <strong><em><a href="https://github.com/sebastienros/jint">Jint</a></em></strong> with features that are not part of the ECMAScript standard, but use full when mixing C# and JavaScript in the same application. </p>
<p>Jint.Ex intend to be as portable as Jint and therefore should work on Windows, MacOS, iOS, Android and Linux. My current focus is Windows WinForm and iOS UIKit with the Xamarin tools.</p>
<ul>
<li><p><strong><em>Event-driven interaction</em></strong>: Jint.Ex.AsyncronousEngine is an event-driven interaction run time for Jint to build non blocking UI and creating asynchronous API with a focus on Windows and iOS.</p></li>
<li><p><strong><em>setTimeOut() and setInterval()</em></strong>: The methods setTimeOut() and setInterval() are part of Browser DOM standard and not part on Jint.
Jint.Ex.AsyncronousEngine offer the methods as well as the clearTimeOut() and clearInterval() methods.</p></li>
<li><p><strong><em>localeStorage</em></strong>: A singleton object compatible with the HTML5 storage standard. Not available yet.</p></li>
</ul>
<h2>Features</h2>
<h3>setTimeout and clearTimeOut</h3>
<p>The methods setTimeout() and clearTimeOut() are not part of the JavaScript language,
but part of the DOM. Nevertheless they can be usefull and sometime necessary
to run some JavaScript libraries written for the browser.
These methods are also present in NodeJs.</p>
<h4>Javascript</h4>
<p>```javascript
function f3() {
print('Hi 3');
}
var timeout3 = setTimeout(f3, 3000);</p>
<p>function f1() {
print('Hi 1');
}
var timeout1 = setTimeout(f1, 1000);</p>
<p>clearTimeout(timeout3);
print('timeout3 cleared');
```</p>
<h4>CSharp</h4>
<p>```csharp
static void SetIntervalDemo()
{
Console.WriteLine("Jint setInterval() demo");</p>
<pre><code>AsyncronousEngine.EmbedScriptAssembly = Assembly.GetExecutingAssembly();
AsyncronousEngine.RequestExecution("setIntervalSetTimeout.js");
AsyncronousEngine.Wait(); // Wait util all events are processed
AsyncronousEngine.Stop(); // Stop the event loop
Console.ReadKey();
</code></pre>
<p>}
```</p>
<h3>setInterval and clearInterval</h3>
<h4>Javascript</h4>
<p>```javascript
function f1() {
print('Hi 1 '+(new Date()));
}
var timeout1 = setInterval(f1, 1000);</p>
<p>function f2() {
print('Hi 2 '+(new Date()));
}
var timeout2 = setInterval(f2, 3000);
```</p>
<h3>Implementing Custom Asynchronous Api</h3>
<p>Jint allows to expose C# methods, class and singleton object to the JavaScript world. With Jint.Ex
you can implement true asynchronous method, like the method read() of the singleton object storage in sample below.</p>
<p><code>javascript
var s = null;
storage.read(function(data) {
s = data;
});
</code></p>
<p>The method read() starts a background thread and returns right away. The thread will execute the read
operation and then request the execution of the call back function using the Jint.Ex event loop.
when the Jint.Ex event loop will reach the event it will execute the call back function.</p>
<p>For more information see blog: xxxxxxxxxxxxxxxxx.</p>
<h3>Jint.Ex Api</h3>
<h4>The AsyncronousEngine class.</h4>
<p>The class AsyncronousEngine allows to run JavaScript script in a background thread
and supports interaction with UI and the execution of the asynchronous events.</p>
<p>```csharp</p>
<p>public static AsyncronousEngine {</p>
<pre><code>/// <summary>
/// The instance of Jint
/// </summary>
public Jint.Engine Engine = null;
/// <summary>
/// Reference the assembly that embed the JavaScript scripts.
/// </summary>
public Assembly EmbedScriptAssembly = null;
/// <summary>
/// Load a file from the file system or as an embed resource
/// </summary>
/// <param name="name"></param>
/// <param name="source"></param>
public void LoadScript(string name, StringBuilder source);
/// <summary>
/// Start the event loop
/// </summary>
/// <returns></returns>
public bool Start();
/// <summary>
/// Request the execution of one javaScript script file by the event loop.
/// The method returns right away.
/// Start the AsyncronousEngine if needed.
/// </summary>
/// <param name="fileName">The filename or resource name to load and execute</param>
/// <param name="block">If true after the execution, block until the event queue is empty</param>
public bool RequestFileExecution(string fileName, bool block = false);
/// <summary>
/// Request the execution of one javaScript source by the event loop.
/// The method returns right away.
/// Start the AsyncronousEngine if needed.
/// </summary>
/// <param name="fileName">The filename or resource name to load and execute</param>
/// <param name="block">If true after the execution, block until the event queue is empty</param>
public bool RequestScriptExecution(string source, bool block = false);
/// <summary>
/// Kill the event loop
/// </summary>
public void Kill();
/// <summary>
/// Stop the event loop
/// </summary>
public void Stop();
/// <summary>
/// Wait until the event queue is empty
/// </summary>
public void Wait();
/// <summary>
/// Clear the event queue
/// </summary>
public void RequestClearQueue();
/// <summary>
/// Request the execution of a JavaScript callback function. This method should be called by
/// C# custom object that want to implement asynchronous api.
/// </summary>
/// <param name="callBackFunction"></param>
/// <param name="parameters"></param>
public void RequestCallbackExecution(Func<Jint.Native.JsValue, Jint.Native.JsValue[], Jint.Native.JsValue> callBackFunction, List<JsValue> parameters);
</code></pre>
<p>}</p>
<p>```</p>