UNPKG

ember-cli-lunr

Version:

Simple full-text search for ember-cli apps.

36 lines (28 loc) 1.01 kB
import { inject as service } from '@ember/service'; import Mixin from '@ember/object/mixin'; import { on } from '@ember/object/evented'; export default Mixin.create({ lunr: service(), init() { this._super(...arguments); this.concatenatedProperties = ['indexableKeys']; this.indexableKeys = ['id']; }, indexRecord: on('didCreate', 'didLoad', function() { var type = this.constructor.modelName, indexableKeys = this.get('indexableKeys'), data = this.getProperties.apply(this, indexableKeys); this.get('lunr').add(type, data); }), reindexRecord: on('didReload', 'didUpdate', function() { var type = this.constructor.modelName, indexableKeys = this.get('indexableKeys'), data = this.getProperties.apply(this, indexableKeys); this.get('lunr').update(type, data); }), unindexRecord: on('willDestroy', function() { var type = this.constructor.modelName, id = this.get('id'); this.get('lunr').remove(type, id); }) });