Skip to content
Snippets Groups Projects
node.js 905 B
Newer Older
  • Learn to ignore specific revisions
  • import Component from '@glimmer/component';
    import { action } from '@ember/object';
    
    
    export default class NodeComponent extends Component {
    
    Eugen Ciur's avatar
    Eugen Ciur committed
      /**
       * Receives arguments:
       * `selectedNodes` - an array of currently selected nodes
       * `model` - current node's model
      */
    
      get is_selected() {
        let model = this.args.model,
          nodes = this.args.selectedNodes;
    
        if (nodes.includes(model)) {
          return true;
        }
    
        return false;
      }
    
      set is_selected(value) {
        // if this node is selected or not is determened
        // by parent component via this.args.selectedNodes
        // array
      }
    
    
      @action
      onCheckboxChange(event) {
        let is_checked = event.target.checked;
    
    
    Eugen Ciur's avatar
    Eugen Ciur committed
        // Notify parent componet that selection change.
        // Parent component will update array of selected Nodes
    
        this.args.onCheckboxChange({
          node: this.args.model,
          is_selected: is_checked
        });
      }
    }