Skip to content
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

improve: add callback as an optional argument to handle eval_js result #769

Merged
merged 3 commits into from Nov 9, 2020

Conversation

shiqimei
Copy link
Contributor

@shiqimei shiqimei commented Nov 9, 2020

This PR tries to provide an optional argument callback_name to the function firenvim#eval_js.

The new signature of this function will be like the following:

firenvim#eval_js(code: string, callback_name?: string)

In this way, we can handle the result of the javascript evaluation in the vim script.

Usages

function EvalJSCallback(result)
    echom 'result' a:result
endfunction

function EvalJS()
    let js = "location.href"
    call firenvim#eval_js(js, 'EvalJSCallback')
endfunction

output: result "https://www.google.com"

function EvalJSCallback(result)
    echom 'result' a:result
endfunction

function EvalJS()
    let js = "new Promise(resolve => fetch('https://jsonplaceholder.typicode.com/todos/1').then(response => response.json()).then(resolve))"
    call firenvim#eval_js(js, 'EvalJSCallback')
endfunction

output: result {"userId":1,"id":1,"title":"delectus aut autem","completed":false}

@glacambre
Copy link
Owner

@lolimay Thanks a lot for taking the time to implement this feature! It unearthed a couple of bugs elsewhere which are now fixed :).

@glacambre glacambre merged commit bcb711c into glacambre:master Nov 9, 2020
@shiqimei shiqimei deleted the eval_js-callback branch November 9, 2020 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants