Skip to content

Commit 424f0d0

Browse files
authored
Update README.md
1 parent ab294ec commit 424f0d0

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

README.md

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ What's New on 1.1
1313

1414
- New Async/Await or Promise API
1515
- New Python classes to expose JS API and Objects like DOM API, XHR, Node.JS require, and etc
16+
- New Python promise class to wait promises with emscripten_sleep, using Emterpreter
1617

1718

1819
Running with Node.js
@@ -60,10 +61,31 @@ import mp_js from 'micropython';
6061
})();
6162
```
6263

63-
API
64+
65+
Python API
66+
---
67+
68+
The following functions and classes is used to interact with Javascript. Load this API with ```mp_js.init_python(stack_size)```
69+
70+
```python
71+
JS(variable_name)
72+
```
73+
Check for variable on Javascript's global and return the corresponding types, functions and Javascript objects instantiate JSFunction and JSObject class. Promise instantiate JSPromise class.
74+
75+
```python
76+
wait(promise)
77+
```
78+
Wait for a promise to be resolved on Javascript, and then returns the value. Uses emscripten_sleep. Also available as JSPromise class function:
79+
80+
```python
81+
response = JS('require')('node-fetch')('https://github.com').wait() #Returns response object
82+
html = response.text().wait() #Returns HTML string
83+
```
84+
85+
Javascript API
6486
---
6587

66-
The following functions have been exposed to javascript.
88+
The following functions have been exposed to Kavascript.
6789

6890
```
6991
init(stack_size)
@@ -96,7 +118,7 @@ will execute MicroPython code when necessary.
96118
init_python(stack_size)
97119
```
98120

99-
NEW!! This function execute js.py to expose JS API to Python, even some helper function and experimental asynchronous queue/stack logic. Example:
121+
NThis function execute js.py to expose JS API to Python, even some helper function and experimental asynchronous queue/stack logic. Example:
100122

101123
```javascript
102124
mp_js = require('micropython');
@@ -108,22 +130,16 @@ mp_js = require('micropython');
108130
109131
import js
110132
111-
#This function executes every line but exit the event loop if wait function is called and resumes after it resolve
112-
exec("""
113-
114133
fetch = False
115134
if isbrowser:
116135
fetch = JS('fetch')
117136
else:
118137
require = JS('require')
119138
fetch = require('node-fetch')
120-
response = fetch('https://github.com')
121-
response = wait(response)
122-
result = response.text()
123-
result = wait(result)
139+
response = fetch('https://github.com').wait()
140+
result = response.text().wait()
124141
print(result)
125-
126-
""")
142+
127143
`);
128144
})();
129145
```

0 commit comments

Comments
 (0)