GithubHelp home page GithubHelp logo

Comments (3)

wlievens avatar wlievens commented on June 9, 2024 1

This works, though I'm sure it's possible to write it shorter and/or more ideomatically:

inputs: ports => (data, connections) => {
    const inputs = [];
    const inputIndexes = Object.keys(connections.inputs).map(input => parseInt(input.substring('flow'.length)));
    const maxIndex = inputIndexes.length > 0 ? Math.max(...inputIndexes) : 1;
    for (let index = 1; index <= maxIndex; ++index) {
        inputs.push(ports.flow({
            name: `flow${index}`,
            label: `Flow [${index}]`
        }));
    }
    const links = connections.inputs[inputs[inputs.length - 1].name];
    if (links && links.length > 0) {
        const index = maxIndex + 1;
        inputs.push(ports.flow({
            name: `flow${index}`,
            label: `Flow [${index}]`
        }));
    }
    return inputs;
}

from flume.

chrisjpatty avatar chrisjpatty commented on June 9, 2024

Thanks! Yeah so the function signature for dynamic inputs actually includes the connections as a second parameter. Let me know if that isn't working on your end: https://flume.dev/docs/flume-config#advanced-inputs-usage.

from flume.

wlievens avatar wlievens commented on June 9, 2024

I seem to have missed that, thanks. This works great

inputs: ports => (data, connections) => {
    const inputs = [];
    let index = 1;
    while (true) {
        const name = `flow${index}`;
        inputs.push(ports.flow({
            name: name,
            label: `Flow [${index}]`
        }));
        const links = connections.inputs[name];
        if (links === undefined || links.length === 0) {
            break;
        }
        index = index + 1
    }
    return inputs;
}

Update: well not quite but that's my fault - if I disconnect an earlier input it kills the one after. I'll improve the code and repost it here for follow-up, but as far as I'm concerned this ticket can be closed.

from flume.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.