src/style_manager/view/LayersView.js
/**
   * Add new object to collection
   * @param Object Model
   * @param Object Fragment collection
   * @param  {number} index Index of append
   *
   * @return Object Object created
   * */
Add new object to collection
@param Object Model
@param Object Fragment collection
@param  {number} index Index of append

@return Object Object created
Add new object to collection @param Object Model @param Object Fragment collection @param { number } index Index of append @return Object Object created
addToCollection(model, fragmentEl, index) {
    var fragment = fragmentEl || null;
    const stackModel = this.stackModel;
    const config = this.config;
    const sorter = this.sorter;
    const propsConfig = this.propsConfig;
    if (typeof this.preview !== 'undefined') {
      model.set('preview', this.preview);
    }
    var view = new LayerView({
      model,
      config,
      sorter,
      stackModel,
      propsConfig
    });
    var rendered = view.render().el;
    if (fragment) {
      fragment.appendChild(rendered);
    } else {
      if (typeof index != 'undefined') {
        var method = 'before';
        if (this.$el.children().length == index) {
          index--;
          method = 'after';
        }
        if (index < 0) {
          this.$el.append(rendered);
        } else
          this.$el
            .children()
            .eq(index)
            [method](rendered);
      } else this.$el.append(rendered);
    }
    return rendered;
  }
addToCollection ( model , fragmentEl , index ) { var fragment = fragmentEl || null ; const stackModel = this . stackModel ; const config = this . config ; const sorter = this . sorter ; const propsConfig = this . propsConfig ; if ( typeof this . preview !== 'undefined' ) { model . set ( 'preview' , this . preview ) ; } var view = new LayerView ( { model , config , sorter , stackModel , propsConfig } ) ; var rendered = view . render ( ) . el ; if ( fragment ) { fragment . appendChild ( rendered ) ; } else { if ( typeof index != 'undefined' ) { var method = 'before' ; if ( this . $el . children ( ) . length == index ) { index -- ; method = 'after' ; } if ( index < 0 ) { this . $el . append ( rendered ) ; } else this . $el . children ( ) . eq ( index ) [ method ] ( rendered ) ; } else this . $el . append ( rendered ) ; } return rendered ; }
Add new object to collection
 @param Object Model
 @param Object Fragment collection
 @param  {number} index Index of append
Add new object to collection @param Object Model @param Object Fragment collection @param { number } index Index of append
// If the added model is the last of collection // need to change the logic of append // In case the added is new in the collection index will be -1