Register Node

Node?

  • This is where we define our node structure like input/output/properties, title, and description

  • Can be ported easily on different programming languages

    • That's mean we can't call specific language's API

    • Any interaction with specific language's API like input/output must be registered on Interface.

    • This supposed to run on NodeJS too, so don't control any HTML element directly inside this.

    • Don't declare or use variable outside of function context/scope.

  • Just think you want to create a compatible logic to be ported on Browser/Node.js/PHP/Python.

  • Just let this node control and communicate with your registered interface.

// Register a new node
// -> (namespace, callback)
Blackprint.registerNode('math/multiply', function(node, iface){
    // node = Blackprint flow handler
    // iface = ScarletsFrame element handler

    // Give it a title
    iface.title = "Random";

    // Give it a description
    iface.description = "Multiply something";

    // If the node would have value that can be exported to JSON
    // It must being set inside options object
    iface.options = {};

    //> We will use `default` node type, so let this empty or undefined
    // iface.interface = 'bp/default';

    // ... Other information below ...
});

Reserved handler property

node here is the Blackprint flow handler from the example above.

Below are reserved property that filled with function/callback

For the detailed example you can see from this repository.

Node port registration

The port must be registered on the node and Blackprint will create internal control with ScarletsFrame so the port can being used for sending or obtaining data from other node's port.

// ========= Port Format ==========
// ... = { PortName: DataType }

// Output port
node.outputs = {
    // Declare Result as a output with Number data type
    Result : Number,

    // Declare Finish for trigger to other connected port's input callback
    Finish : Function

    // Output can have many connection into the related input data type
};

// Input port
// Let's declare as `inputs` variable too, for easy access
var inputs = node.inputs = {
    // Declare A and validate this input as Number data type
    A : Number, // Primitive type can only have one cable connected

    // Declare B that will being called if any value
    // on connected output port was updated
    B : Blackprint.PortValidator(Number, function(value, Port){
        // value === Port.value
    }),

    // Declare Start as a callback to start the multiplication
    // Can have many cable connected
    Start : function(/* arguments */){
        // arguments are passed from the caller/output port of connected node

        // Let's call declared function below
        startMultiply();
    },

    // Accept Array of Number, can have many cable connected
    C : Blackprint.PortArrayOf(Number),
};

function startMultiply(){
    node.outputs.Result = inputs.A * inputs.B;

    node.outputs.Finish("We can send", "arguments too");
}

Last updated