Update interactions, removed image and added in the correct event
import { bindable, inject } from 'aurelia-framework';
import Masonry from 'masonry-layout';
import { EventAggregator } from 'aurelia-event-aggregator';
import { RefreshedView } from 'resources/messages';
import { Router } from 'aurelia-router';

@inject(EventAggregator, Router)
export class InteractionListCustomElement {
  @bindable interactions = null;

  constructor(ea, router) {
    this.ea = ea;
    this.theRouter = router;
    this.viewRefreshed = ea.subscribe(RefreshedView, msg => this.createMasonry());
  }

  isAttached = false;

  attached() {
    this.isAttached = true;
    this.createMasonry();
  }

  detached() {
    this.viewRefreshed();
    this.msnry.destroy();
  }

  loadUserRoute(user) {
    this.theRouter.navigateToRoute("userprofile", { user_id: user });
  }

  createMasonry() {
    var container = document.querySelector('#posts');

    this.msnry = new Masonry(container, {
      columnWidth: ".post",
      itemSelector: '.post',
      percentPosition: true,
      gutter: 10
    });
  }

  postsChanged() {
    if (this.isAttached) {
      this.createMasonry();
    }
  }
}
import { bindable, inject } from 'aurelia-framework';
import imagesLoaded from 'imagesloaded';
import Masonry from 'masonry-layout';
import { EventAggregator } from 'aurelia-event-aggregator';
import { RefreshView } from 'resources/messages';

@inject(EventAggregator)
export class InteractionListCustomElement {
  @bindable interactions = null;
  
  constructor(ea) {
    this.ea = ea;
    this.refreshView = ea.subscribe(RefreshView, msg => this.createMasonry());
  }

  isAttached = false;

  attached() {
    this.isAttached = true;
    this.createMasonry();
  }

  createMasonry() {
    var container = document.querySelector('#posts');

    imagesLoaded(container, function () {
      var msnry = new Masonry(container, {
        columnWidth: ".post",
        itemSelector: '.post',
        percentPosition: true,
        gutter: 10
      });
    });
  }
  
  postsChanged() {
    if (this.isAttached) {
      this.createMasonry();       
    }
  }
}