-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Universal reader #499
Universal reader #499
Conversation
👍Sounds like a good idea! Shall we make a var req = new XMLHttpRequest().
req.open( "GET", url, false ); // false for synchronous request The Are we going to stop exposing the |
Agreed! I think we can use async in the external and expose a new blocking method. Then we don't need to worry to much about supporting both :)
Sure. But maybe we need further discussion about this. The current IDE uses an bundled examples object for the reader. Should we change it to http requests or we may expose a new option for injecting the import context once we stop exposing the reader option. |
Should we use
or
IMO, I would prefer the former one since it better matches with node's APIs. But on the other hand, the latter seems more straightforward. |
Personally I like |
So maybe let's go with |
Bad News: making async function sync seems to be impossible in the browser. I was trying to make compile from compileAsync using https://www.npmjs.com/package/synchronized-promise and it works fine in node. It actually using some C++ binary to do the hack and there is no luck for the browser. (I did some research and there seems to be not alternative for that) Maybe we should use |
Hi @antfu, I think you could do this: function fetchTextSync(theUrl){
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
xmlHttp.send( null );
return xmlHttp.responseText;
}
console.log(fetchTextSync("https://raw.githubusercontent.com/LingDong-/wenyan-lang/master/lib/%E7%AE%97%E7%B6%93.wy"))
// prints the content of 算經 to the console. I guess in |
Normally I would not suggest to use deprecating apis, but your solution seems to work perfectly fine. I have changed all the functions back to sync mode as they did before.👍 |
It's ready! :P |
Goal
To make importing script much easier. #154 #100
Solutions
compile
-importPaths: string[]
, providing a list of directories paths for searching modules to import.importPaths
to["https://raw.githubusercontent.com/LingDong-/wenyan-lang/master/examples/"]
to load examples from github.reader
will search in the order ofimportPath
, the first hit will get returned.cli
will automatically add the script parent dir and current working dir toimportPaths
runtime
will automatically add the root for the website toimportPaths
Examples
The following example will search for local examples first, if not found, will fallback to online examples.
Changes
reader
,extractMacros
become async functions in order to wait for requests.compileAsync
,executeAsync
is added.Considerations
--allow-http
options (default to false) for better secure purpose (loading arbitrate code from web can be vulnerable )trustedHosts
and includinghttps://raw.githubusercontent.com/LingDong-/wenyan-lang/master
to load from official repo etc.TODO
useaxios
instead offetch()
for better compiltbily.Async versioncompileAsync
executeAsync
(https://github.com/Yukaii/synchronized-promise)Please feel free to leave any comments!