marko-js / marko

A declarative, HTML-based language that makes building web apps fun
https://markojs.com/
MIT License
13.35k stars 643 forks source link

Passing `arg-*` to the `await` tag does not inject arguments into the target method. #943

Closed NotJustClarkKent closed 4 years ago

NotJustClarkKent commented 6 years ago

Bug Report

Marko Version: 4.7.0

Details

Passing arg-* to the await tag does not inject arguments into the target method.

Expected Behavior

Arguments passed via await tag attributes are injected into the target method.

Actual Behavior

Arguments passed via await tag attributes are not injected into the target method.

Possible Fix

Within await-tag.js, using the same call on the provider rather than using a conditional seems to fix the issue but I'm sure this statement existed to resolve another problem so I'm not confident this will be the fix.

// marko/src/taglibs/async/await-tag.js
var value = (provider.length === 1) ?
    // one argument so only provide callback to function call

    // [FIX] (`args` added)
    provider.call(thisObj, args, callback) :

    // two arguments so provide args and callback to function call
    provider.call(thisObj, args, callback);

Your Environment

Steps to Reproduce

  1. Create a new component with Try Online or local dev environment that depends on await:
    
    $ input = { duration: 5000, error: false };
    $ function wasteTime({ duration, error }) {
    console.log('arg error:', error);
    console.log('arg duration:', duration);  
    if (error) return Promise.reject('failed');
    return new Promise((resolve) => setTimeout(resolve, duration * 1000)).then(() => 'done!');
    }

<await(result from wasteTime) arg-duration=input.duration arg-error=input.error>

[ spinner ]
Request timed out
Something bad happened!
I loaded after ${input.duration} seconds with: ${result}


2. Check the console, both arguments (`duration`, `error`) are undefined.
3. If you're running this locally, modify the line identified under "Possible Fix" and re-run the same code successfully.

### Stack Trace
N/A
</details>
DylanPiercey commented 4 years ago

The await tag has been updated to remove these clunkier parts of the API see https://markojs.com/docs/core-tags/#await

Using the marko migrate command in marko-cli will automatically update the existing syntax.