adamrenklint/bap

View on GitHub
lib/mixins/connectable.js

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
module.exports = {

  props: {
    connections: ['array', true, function () { return []; }]
  },

  connect: function (node) {
    this.connections = this.connections.concat(node);
    return this;
  },

  disconnect: function (node) {
    if (Array.isArray(node)) {
      this.connections = this.connections.filter(function (connection) {
        return !~node.indexOf(connection);
      });
    }
    else if (node) {
      this.connections = this.connections.filter(function (connection) {
        return node !== connection;
      });
    }
    else {
      this.connections = [];
    }
    return this;
  }
};