const store = require('../../utils/store.js'); Component({ options: { addGlobalClass: true }, data: { pets: [], currentId: 0, }, lifetimes: { attached() { this.refresh(); this._unsub = store.subscribe(() => this.refresh()); }, detached() { if (this._unsub) this._unsub(); }, }, methods: { refresh() { this.setData({ pets: store.getPets(), currentId: store.currentPetId() || 0, }); }, onPick(e) { const id = e.currentTarget.dataset.id; store.switchPet(id); this.triggerEvent('change', { id }); }, onAdd() { this.triggerEvent('add'); }, }, });