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

'ins' command should accept 'g2' objects #35

Open
goessner opened this issue Jul 27, 2019 · 0 comments
Open

'ins' command should accept 'g2' objects #35

goessner opened this issue Jul 27, 2019 · 0 comments
Assignees

Comments

@goessner
Copy link
Owner

It is implemented by

    ins(arg) {
        return typeof arg === 'function' ? (arg(this) || this)                   // no further processing by handler ...
             : typeof arg === 'object'   ? ( this.commands.push({a:arg}), this ) // no explicit command name .. !
             : this;
    },

and

    async exe(commands) {
        for (let cmd of commands) {
            if (cmd.c && this[cmd.c]) {         // explicit command name .. !
                const rx = this[cmd.c](cmd.a);
                if (rx && rx instanceof Promise) {
                    await rx;
                }
            } else if (cmd.a) {                 // should be from 'ins' command
                if (cmd.a.commands)                // cmd.a is a `g2` object, so directly execute its commands array.
                    this.exe(cmd.a.commands);
                if (cmd.a.g2)                      // cmd.a is an object offering a `g2` method, so call it and execute its returned commands array.
                    this.exe(cmd.a.g2().commands);
            }
        }
    },

Please add and test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants