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

xtemplate: support async command #587

Closed
yiminghe opened this issue Mar 24, 2014 · 0 comments
Closed

xtemplate: support async command #587

yiminghe opened this issue Mar 24, 2014 · 0 comments
Milestone

Comments

@yiminghe
Copy link
Member

it('can combine inline command and block async command', function () {
    var tpl = '{{#async(1)}}{{upperCase(asyncContent)}}{{/async}}';
    var ret = '';
    expect(new XTemplate(tpl, {
        commands: {
            async: function (scope, option, buffer) {
                var newScope = new this.Scope();
                newScope.setParent(scope);
                return buffer.async(function (asyncBuffer) {
                    setTimeout(function () {
                        newScope.setData({
                            asyncContent: option.params[0] + ' ok'
                        });
                        option.fn(newScope, asyncBuffer).end();
                    }, 100);
                });
            },
            'upperCase': function (scope, option) {
                return option.params[0].toUpperCase();
            }
        }
    }).render({ }, function (error, content) {
            ret = content;
        })).toBe('');
    waitsFor(function () {
        return ret;
    });
    runs(function () {
        expect(ret).toBe('1 OK');
    });
});
@yiminghe yiminghe added this to the 5.0.0 milestone Apr 24, 2014
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

No branches or pull requests

1 participant