Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Boxiang Sun
erp5
Commits
f9495a51
Commit
f9495a51
authored
Jul 15, 2019
by
Boxiang Sun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_notebook: Use RSVP.defer to avoid create Promise manually
parent
b14231fc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
92 additions
and
62 deletions
+92
-62
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.css.css
...eItem/portal_skins/erp5_notebook/gadget_jsmd_eval.css.css
+7
-0
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.css.xml
...eItem/portal_skins/erp5_notebook/gadget_jsmd_eval.css.xml
+28
-0
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html
...tem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html
+1
-0
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js
...ateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js
+56
-62
No files found.
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.css.css
0 → 100644
View file @
f9495a51
div
.code-block
{
border-width
:
1px
;
border-style
:
solid
;
border-color
:
#C3CCD0
;
margin
:
40px
10px
;
padding-left
:
10px
;
}
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.css.xml
0 → 100644
View file @
f9495a51
<?xml version="1.0"?>
<ZopeData>
<record
id=
"1"
aka=
"AAAAAAAAAAE="
>
<pickle>
<global
name=
"File"
module=
"OFS.Image"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
__name__
</string>
</key>
<value>
<string>
gadget_jsmd_eval.css
</string>
</value>
</item>
<item>
<key>
<string>
content_type
</string>
</key>
<value>
<string>
text/css
</string>
</value>
</item>
<item>
<key>
<string>
precondition
</string>
</key>
<value>
<string></string>
</value>
</item>
<item>
<key>
<string>
title
</string>
</key>
<value>
<string></string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html
View file @
f9495a51
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
<meta
name=
"viewport"
content=
"width=device-width"
/>
<meta
name=
"viewport"
content=
"width=device-width"
/>
<title>
JSMD Eval Gadget
</title>
<title>
JSMD Eval Gadget
</title>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"gadget_jsmd_eval.css"
/>
<script
src=
"rsvp.js"
type=
"text/javascript"
></script>
<script
src=
"rsvp.js"
type=
"text/javascript"
></script>
<script
src=
"marked.js"
type=
"text/javascript"
></script>
<script
src=
"marked.js"
type=
"text/javascript"
></script>
...
...
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js
View file @
f9495a51
...
@@ -127,13 +127,12 @@
...
@@ -127,13 +127,12 @@
// can't be done synchronously within the call to dlopen, we instantiate
// can't be done synchronously within the call to dlopen, we instantiate
// every .so that comes our way up front, caching it in the
// every .so that comes our way up front, caching it in the
// `preloadedWasm` dictionary.
// `preloadedWasm` dictionary.
var
queue
,
FS
;
let
promise
=
new
Promise
((
resolve
)
=>
resolve
()
);
queue
=
new
RSVP
.
Queue
(
);
let
FS
=
pyodide
.
_module
.
FS
;
FS
=
pyodide
.
_module
.
FS
;
function
recurseDir
(
rootpath
)
{
function
recurseDir
(
rootpath
)
{
let
dirs
;
var
entry
,
dirs
;
var
entry
;
try
{
try
{
dirs
=
FS
.
readdir
(
rootpath
);
dirs
=
FS
.
readdir
(
rootpath
);
}
catch
{
}
catch
{
...
@@ -146,14 +145,16 @@
...
@@ -146,14 +145,16 @@
const
path
=
rootpath
+
entry
;
const
path
=
rootpath
+
entry
;
if
(
entry
.
endsWith
(
'
.so
'
))
{
if
(
entry
.
endsWith
(
'
.so
'
))
{
if
(
Module
[
'
preloadedWasm
'
][
path
]
===
undefined
)
{
if
(
Module
[
'
preloadedWasm
'
][
path
]
===
undefined
)
{
promise
=
promise
queue
.
push
(
function
()
{
.
then
(()
=>
Module
[
'
loadWebAssemblyModule
'
](
return
Module
[
'
loadWebAssemblyModule
'
](
FS
.
readFile
(
path
),
{
FS
.
readFile
(
path
),
{
loadAsync
:
true
loadAsync
:
true
}))
}
.
then
((
module
)
=>
{
)
Module
[
'
preloadedWasm
'
][
path
]
=
module
;
})
});
.
push
(
function
(
module
)
{
Module
[
'
preloadedWasm
'
][
path
]
=
module
;
});
}
}
}
else
if
(
FS
.
isDir
(
FS
.
lookupPath
(
path
).
node
.
mode
))
{
}
else
if
(
FS
.
isDir
(
FS
.
lookupPath
(
path
).
node
.
mode
))
{
recurseDir
(
path
+
'
/
'
);
recurseDir
(
path
+
'
/
'
);
...
@@ -163,16 +164,17 @@
...
@@ -163,16 +164,17 @@
recurseDir
(
'
/
'
);
recurseDir
(
'
/
'
);
return
promis
e
;
return
queu
e
;
}
}
function
pyodideLoadPackage
(
names
)
{
function
pyodideLoadPackage
(
names
)
{
// DFS to find all dependencies of the requested packages
// DFS to find all dependencies of the requested packages
var
queue
,
toLoad
,
package_uri
,
package_name
,
k
,
var
queue
,
toLoad
,
package_uri
,
package_name
,
k
,
subpackage
,
p
romise
,
packageList
,
script
;
subpackage
,
p
ackageList
,
script
,
defer
;
packages
=
window
.
pyodide
.
packages
.
dependencies
;
packages
=
window
.
pyodide
.
packages
.
dependencies
;
queue
=
new
Array
(
names
);
queue
=
new
Array
(
names
);
toLoad
=
[];
toLoad
=
[];
defer
=
RSVP
.
defer
();
while
(
queue
.
length
)
{
while
(
queue
.
length
)
{
package_uri
=
queue
.
pop
();
package_uri
=
queue
.
pop
();
package_name
=
_uri_to_package_name
(
package_uri
);
package_name
=
_uri_to_package_name
(
package_uri
);
...
@@ -208,47 +210,49 @@
...
@@ -208,47 +210,49 @@
}
}
}
}
promise
=
new
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
if
(
Object
.
keys
(
toLoad
).
length
===
0
)
{
if
(
Object
.
keys
(
toLoad
).
length
===
0
)
{
console
.
log
(
'
No new packages to load
'
);
re
solve
(
'
No new packages to load
'
)
;
re
turn
;
}
}
pyodide
.
monitorRunDependencies
=
function
(
n
)
{
pyodide
.
monitorRunDependencies
=
function
(
n
)
{
if
(
n
===
0
)
{
if
(
n
===
0
)
{
for
(
package_name
in
toLoad
)
{
for
(
package_name
in
toLoad
)
{
loadedPackages
[
package_name
]
=
toLoad
[
package_name
];
loadedPackages
[
package_name
]
=
toLoad
[
package_name
];
}
delete
pyodide
.
monitorRunDependencies
;
packageList
=
Array
.
from
(
Object
.
keys
(
toLoad
)).
join
(
'
,
'
);
preloadWasm
().
then
(()
=>
{
resolve
(
`Loaded
${
packageList
}
`
)
});
}
}
};
delete
pyodide
.
monitorRunDependencies
;
packageList
=
Array
.
from
(
Object
.
keys
(
toLoad
)).
join
(
'
,
'
);
function
script_reject
(
e
)
{
return
preloadWasm
()
reject
(
e
);
.
push
(
function
()
{
defer
.
resolve
();
console
.
log
(
'
Loaded
'
+
packageList
);
return
;
});
}
}
};
for
(
package_name
in
toLoad
)
{
function
script_reject
(
e
)
{
script
=
document
.
createElement
(
'
script
'
);
defer
.
reject
(
e
);
package_uri
=
toLoad
[
package_name
];
}
if
(
package_uri
===
'
default channel
'
)
{
script
.
src
=
package_name
+
"
.js
"
;
for
(
package_name
in
toLoad
)
{
}
else
{
script
=
document
.
createElement
(
'
script
'
);
script
.
src
=
package_uri
;
package_uri
=
toLoad
[
package_name
];
}
if
(
package_uri
===
'
default channel
'
)
{
script
.
onerror
=
script_reject
;
script
.
src
=
package_name
+
"
.js
"
;
document
.
body
.
appendChild
(
script
);
}
else
{
script
.
src
=
package_uri
;
}
}
script
.
onerror
=
script_reject
;
document
.
body
.
appendChild
(
script
);
}
// We have to invalidate Python's import caches, or it won't
// We have to invalidate Python's import caches, or it won't
// see the new files. This is done here so it happens in parallel
// see the new files. This is done here so it happens in parallel
// with the fetching over the network.
// with the fetching over the network.
window
.
pyodide
.
runPython
(
'
import importlib as _importlib
\n
'
+
window
.
pyodide
.
runPython
(
'
import importlib as _importlib
\n
'
+
'
_importlib.invalidate_caches()
\n
'
);
'
_importlib.invalidate_caches()
\n
'
);
});
return
defer
.
promise
;
return
promise
;
}
}
function
parseJSMDCellList
(
jsmd
)
{
function
parseJSMDCellList
(
jsmd
)
{
...
@@ -479,9 +483,7 @@
...
@@ -479,9 +483,7 @@
var
div
=
document
.
createElement
(
'
div
'
),
var
div
=
document
.
createElement
(
'
div
'
),
pre
=
document
.
createElement
(
'
pre
'
),
pre
=
document
.
createElement
(
'
pre
'
),
result
=
document
.
createElement
(
'
code
'
);
result
=
document
.
createElement
(
'
code
'
);
div
.
style
.
border
=
'
1px solid #C3CCD0
'
;
div
.
classList
.
add
(
'
code-block
'
);
div
.
style
.
margin
=
'
40px 10px
'
;
div
.
style
.
paddingLeft
=
'
10px
'
;
if
(
result_text
!==
undefined
)
{
if
(
result_text
!==
undefined
)
{
result
.
innerHTML
=
result_text
;
result
.
innerHTML
=
result_text
;
...
@@ -497,10 +499,7 @@
...
@@ -497,10 +499,7 @@
result
=
document
.
createElement
(
'
code
'
);
result
=
document
.
createElement
(
'
code
'
);
div
.
setAttribute
(
"
id
"
,
py_div_id_prefix
+
py_div_id_count
);
div
.
setAttribute
(
"
id
"
,
py_div_id_prefix
+
py_div_id_count
);
py_div_id_count
+=
1
;
py_div_id_count
+=
1
;
div
.
classList
.
add
(
'
code-block
'
);
div
.
style
.
border
=
'
1px solid #C3CCD0
'
;
div
.
style
.
margin
=
'
40px 10px
'
;
div
.
style
.
paddingLeft
=
'
10px
'
;
result
.
innerHTML
=
"
Loading pyodide
"
;
result
.
innerHTML
=
"
Loading pyodide
"
;
pre
.
appendChild
(
result
);
pre
.
appendChild
(
result
);
...
@@ -518,14 +517,8 @@
...
@@ -518,14 +517,8 @@
window
.
pyodide
=
pyodide
(
Module
);
window
.
pyodide
=
pyodide
(
Module
);
window
.
pyodide
.
loadPackage
=
pyodideLoadPackage
;
window
.
pyodide
.
loadPackage
=
pyodideLoadPackage
;
var
defer
=
RSVP
.
defer
(),
var
defer
=
RSVP
.
defer
();
promise
=
defer
.
promise
;
Module
.
postRun
=
defer
.
resolve
;
Module
.
postRun
=
defer
.
resolve
;
promise
.
then
(
function
()
{
console
.
log
(
"
postRun get called
"
);
delete
window
.
Module
;
});
return
defer
.
promise
;
return
defer
.
promise
;
}
}
...
@@ -555,6 +548,7 @@
...
@@ -555,6 +548,7 @@
return
pyodideSetting
();
return
pyodideSetting
();
})
})
.
push
(
function
()
{
.
push
(
function
()
{
delete
window
.
Module
;
return
ajax
({
return
ajax
({
url
:
'
packages.json
'
url
:
'
packages.json
'
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment