<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/paper-toast/paper-toast.html">

<polymer-element name="ha-notifications">
  <template>
    <paper-toast id="toast" role="alert" text=""></paper-toast>
  </template>
  <script>
  var storeListenerMixIn = window.hass.storeListenerMixIn;

  Polymer(Polymer.mixin({
    lastId: null,

    attached: function() {
      this.listenToStores(true);
    },

    detached: function() {
      this.stopListeningToStores();
    },

    notificationStoreChanged: function(notificationStore) {
      if (notificationStore.hasNewNotifications(this.lastId)) {
        var toast = this.$.toast;
        var notification = notificationStore.lastNotification;

        this.lastId = notification.id;
        toast.text = notification.message;
        toast.show();
      }
    },

  }, storeListenerMixIn));
  </script>
</polymer-element>

<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/paper-toast/paper-toast.html">

<polymer-element name="ha-notifications">
  <template>
    <paper-toast id="toast" role="alert" text=""></paper-toast>
  </template>
  <script>
  var storeListenerMixIn = window.hass.storeListenerMixIn;

  Polymer(Polymer.mixin({
    lastId: null,

    attached: function() {
      this.listenToStores(true);
    },

    detached: function() {
      this.stopListeningToStores();
    },

    notificationStoreChanged: function(notificationStore) {
      if (notificationStore.hasNewNotifications(this.lastId)) {
        var toast = this.$.toast;
        var notification = notificationStore.lastNotification;

        if (notification) {
          this.lastId = notification.id;
          toast.text = notification.message;
          toast.show();
        }
      }
    },

  }, storeListenerMixIn));
  </script>
</polymer-element>

Fix JS notification error on initialization.
Fix JS notification error on initialization.

The last notification is initially null resulting in an exception being
thrown on startup.
