From daf000f5ae1f0ba736f3c3c412bce6cf19549ca5 Mon Sep 17 00:00:00 2001 From: Jake Harding Date: Sun, 10 Mar 2013 23:00:35 -0700 Subject: [PATCH 1/3] Trigger typeahead:selected on selection. --- Gruntfile.js | 1 + src/dropdown_view.js | 27 +++++++------------ src/event_bus.js | 30 +++++++++++++++++++++ src/typeahead_view.js | 14 ++++++---- test/dropdown_view_spec.js | 52 ++++++++++++++----------------------- test/playground.html | 41 +++++++++++++++++++++++------ test/typeahead_view_spec.js | 16 +++++++++--- 7 files changed, 115 insertions(+), 66 deletions(-) create mode 100644 src/event_bus.js diff --git a/Gruntfile.js b/Gruntfile.js index 62917fc5..cf60a63c 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -4,6 +4,7 @@ var semver = require('semver'), 'src/version.js', 'src/utils.js', 'src/event_target.js', + 'src/event_bus.js', 'src/persistent_storage.js', 'src/request_cache.js', 'src/transport.js', diff --git a/src/dropdown_view.js b/src/dropdown_view.js index b53c7a14..135cf2d2 100644 --- a/src/dropdown_view.js +++ b/src/dropdown_view.js @@ -52,7 +52,7 @@ var DropdownView = (function() { _handleSelection: function($e) { var $suggestion = $($e.currentTarget); - this.trigger('suggestionSelected', formatDataForSuggestion($suggestion)); + this.trigger('suggestionSelected', getSuggestionData($suggestion)); }, _show: function() { @@ -94,7 +94,7 @@ var DropdownView = (function() { } $underCursor = $suggestions.eq(nextIndex).addClass('tt-is-under-cursor'); - this.trigger('cursorMoved', { value: $underCursor.data('value') }); + this.trigger('cursorMoved', getSuggestionData($underCursor)); }, _getSuggestions: function() { @@ -166,15 +166,13 @@ var DropdownView = (function() { .filter('.tt-is-under-cursor') .first(); - return $suggestion.length > 0 ? - formatDataForSuggestion($suggestion) : null; + return $suggestion.length > 0 ? getSuggestionData($suggestion) : null; }, getFirstSuggestion: function() { var $suggestion = this._getSuggestions().first(); - return $suggestion.length > 0 ? - formatDataForSuggestion($suggestion) : null; + return $suggestion.length > 0 ? getSuggestionData($suggestion) : null; }, renderSuggestions: function(query, dataset, suggestions) { @@ -209,7 +207,7 @@ var DropdownView = (function() { $el = $(elBuilder.firstChild) .css(css.suggestion) - .data('value', suggestion.value); + .data('suggestion', suggestion); $el.children().each(function() { $(this).css(css.suggestionChild); @@ -219,9 +217,7 @@ var DropdownView = (function() { }); } - $dataset.find('> .tt-suggestions') - .data({ query: query, dataset: dataset.name }) - .append(fragment); + $dataset.find('> .tt-suggestions').append(fragment); this.trigger('suggestionsRendered'); }, @@ -242,13 +238,10 @@ var DropdownView = (function() { return DropdownView; - function formatDataForSuggestion($suggestion) { - var $suggestions = $suggestion.parents('.tt-suggestions').first(); + // helper functions + // ---------------- - return { - value: $suggestion.data('value'), - query: $suggestions.data('query'), - dataset: $suggestions.data('dataset') - }; + function getSuggestionData($el) { + return $el.data('suggestion'); } })(); diff --git a/src/event_bus.js b/src/event_bus.js new file mode 100644 index 00000000..8c9e325c --- /dev/null +++ b/src/event_bus.js @@ -0,0 +1,30 @@ +/* + * typeahead.js + * https://github.com/twitter/typeahead + * Copyright 2013 Twitter, Inc. and other contributors; Licensed MIT + */ + +var EventBus = (function() { + var namespace = 'typeahead:'; + + function EventBus(o) { + if (!o || !o.el) { + $.error('EventBus initialized without el'); + } + + this.$el = $(o.el); + } + + utils.mixin(EventBus.prototype, { + // public methods + // -------------- + + trigger: function(type) { + var args = [].slice.call(arguments, 1); + + this.$el.trigger(namespace + type, args); + } + }); + + return EventBus; +})(); diff --git a/src/typeahead_view.js b/src/typeahead_view.js index 194da7ae..b7eb10f3 100644 --- a/src/typeahead_view.js +++ b/src/typeahead_view.js @@ -70,6 +70,8 @@ var TypeaheadView = (function() { $input = this.$node.find('.tt-query'); $hint = this.$node.find('.tt-hint'); + this.eventBus = new EventBus({ el: $input }); + this.dropdownView = new DropdownView({ menu: $menu }) .on('suggestionSelected', this._handleSelection) .on('cursorMoved', this._clearHint) @@ -136,8 +138,8 @@ var TypeaheadView = (function() { }, _updateHint: function() { - var dataForFirstSuggestion = this.dropdownView.getFirstSuggestion(), - hint = dataForFirstSuggestion ? dataForFirstSuggestion.value : null, + var suggestion = this.dropdownView.getFirstSuggestion(), + hint = suggestion ? suggestion.value : null, dropdownIsVisible = this.dropdownView.isVisible(), inputHasOverflow = this.inputView.isOverflow(), inputValue, @@ -198,11 +200,11 @@ var TypeaheadView = (function() { _handleSelection: function(e) { var byClick = e.type === 'suggestionSelected', - suggestionData = byClick ? + suggestion = byClick ? e.data : this.dropdownView.getSuggestionUnderCursor(); - if (suggestionData) { - this.inputView.setInputValue(suggestionData.value); + if (suggestion) { + this.inputView.setInputValue(suggestion.value); // if triggered by click, ensure the query input still has focus // if triggered by keypress, prevent default browser behavior @@ -213,6 +215,8 @@ var TypeaheadView = (function() { // focus is not a synchronous event in ie, so we deal with it byClick && utils.isMsie() ? setTimeout(this.dropdownView.close, 0) : this.dropdownView.close(); + + this.eventBus.trigger('selected', suggestion); } }, diff --git a/test/dropdown_view_spec.js b/test/dropdown_view_spec.js index 123f96a2..b73213a6 100644 --- a/test/dropdown_view_spec.js +++ b/test/dropdown_view_spec.js @@ -65,28 +65,20 @@ describe('DropdownView', function() { }); describe('on suggestion click', function() { - beforeEach(function() { this.dropdownView .on('suggestionSelected', this.spy = jasmine.createSpy()); this.$testDataset = renderTestDataset(this.dropdownView, true); - this.$suggestion = this.$testDataset - .data('query', 'test query') - .data('dataset', 'test dataset') - .find('.tt-suggestion:nth-child(1)') - .click(); + this.$suggestion = this.$testDataset.find('.tt-suggestion:nth-child(1)'); + this.$suggestion.click(); }); it('should trigger suggestionSelected', function() { expect(this.spy).toHaveBeenCalledWith({ type: 'suggestionSelected', - data: { - query: 'test query', - dataset: 'test dataset', - value: 'one' - } + data: { value: 'one' } }); }); }); @@ -430,15 +422,16 @@ describe('DropdownView', function() { describe('if suggestion is under the cursor', function() { it('should return obj with data about suggestion under the cursor', function() { - var $suggestion = this.$menu - .find('.tt-suggestion') - .first() - .addClass('tt-is-under-cursor'), - suggestionData = this.dropdownView.getSuggestionUnderCursor(); + var suggestion; + + this.$menu + .find('.tt-suggestion') + .first() + .addClass('tt-is-under-cursor'); + + suggestion = this.dropdownView.getSuggestionUnderCursor(); - expect(suggestionData.value).toBe($suggestion.data('value')); - expect(suggestionData.query).toBe(this.$testDataset.data('query')); - expect(suggestionData.dataset).toBe(this.$testDataset.data('dataset')); + expect(suggestion).toEqual({ value: 'one' }); }); }); }); @@ -450,12 +443,8 @@ describe('DropdownView', function() { it('should return obj with data about suggestion under the cursor', function() { - var $firstSuggestion = this.dropdownView._getSuggestions().first(), - suggestionData = this.dropdownView.getFirstSuggestion(); - - expect(suggestionData.value).toBe($firstSuggestion.data('value')); - expect(suggestionData.query).toBe(this.$testDataset.data('query')); - expect(suggestionData.dataset).toBe(this.$testDataset.data('dataset')); + var suggestion = this.dropdownView.getFirstSuggestion(); + expect(suggestion).toEqual({ value: 'one' }); }); }); @@ -519,17 +508,14 @@ describe('DropdownView', function() { expect(this.dropdownView.clearSuggestions).toHaveBeenCalledWith('test'); }); - it('should update data values on list', function() { - expect(this.$testDataset).toHaveData('query', 'query'); - expect(this.$testDataset).toHaveData('dataset', 'test'); - }); - it('should overwrite previous suggestions', function() { - var $suggestions = this.$testDataset.children(); + var $suggestions = this.$testDataset.children(), + $suggestion = $suggestions.first(), + suggestion = $suggestion.data('suggestion'); expect($suggestions.length).toBe(1); - expect($suggestions.first()).toHaveText('i am a value'); - expect($suggestions.first()).toHaveData('value', 'i am a value'); + expect($suggestion).toHaveText('i am a value'); + expect(suggestion).toEqual({ value: 'i am a value' }); }); it('should trigger suggestionsRendered', function() { diff --git a/test/playground.html b/test/playground.html index 8cc3eeb9..5fc45730 100644 --- a/test/playground.html +++ b/test/playground.html @@ -10,6 +10,11 @@ margin: 50px auto; } + .typeahead-wrapper { + display: block; + margin: 50px 0; + } + .tt-dropdown-menu { background-color: #fff; border: 1px solid #000; @@ -18,18 +23,27 @@ .tt-suggestion.tt-is-under-cursor { background-color: #ccc; } + + .triggered-events { + float: right; + width: 500px; + height: 300px; + }
- -
-
- -
-
- + +
+ +
+
+ +
+
+ +
diff --git a/test/typeahead_view_spec.js b/test/typeahead_view_spec.js index c9c004c3..1a351003 100644 --- a/test/typeahead_view_spec.js +++ b/test/typeahead_view_spec.js @@ -19,10 +19,10 @@ describe('TypeaheadView', function() { setFixtures(fixture); $fixtures = $('#jasmine-fixtures'); - $input = $fixtures.find('.tt-test'); + this.$input = $fixtures.find('.tt-test'); this.typeaheadView = new TypeaheadView({ - input: $input, + input: this.$input, datasets: mockDatasets }); @@ -38,6 +38,8 @@ describe('TypeaheadView', function() { describe('when dropdownView triggers suggestionSelected', function() { beforeEach(function() { + this.spyEvent = spyOnEvent(this.$input, 'typeahead:selected'); + this.dropdownView .trigger('suggestionSelected', { value: 'i am selected' }); }); @@ -54,6 +56,10 @@ describe('TypeaheadView', function() { it('should close dropdown', function() { expect(this.dropdownView.close).toHaveBeenCalled(); }); + + it('should trigger typeahead:selected on the input', function() { + expect(this.spyEvent).toHaveBeenTriggered(); + }); }); describe('when dropdownView triggers cursorMoved', function() { @@ -119,6 +125,7 @@ describe('TypeaheadView', function() { describe('when inputView triggers enterKeyed', function() { beforeEach(function() { this.spy = jasmine.createSpy(); + this.spyEvent = spyOnEvent(this.$input, 'typeahead:selected'); this.dropdownView.getSuggestionUnderCursor .andReturn({ value: 'i am selected' }); @@ -138,6 +145,10 @@ describe('TypeaheadView', function() { it('should close dropdown', function() { expect(this.dropdownView.close).toHaveBeenCalled(); }); + + it('should trigger typeahead:selected on the input', function() { + expect(this.spyEvent).toHaveBeenTriggered(); + }); }); describe('when inputView triggers whitespaceChanged', function() { @@ -470,7 +481,6 @@ describe('TypeaheadView', function() { describe('#destroy', function() { beforeEach(function() { - this.$input = this.typeaheadView.$node.find('.tt-query'); this.typeaheadView.destroy(); }); From 04d8f2a08c5e232b11eba1f6da5c921e8bb4cae2 Mon Sep 17 00:00:00 2001 From: Jake Harding Date: Mon, 11 Mar 2013 09:22:30 -0700 Subject: [PATCH 2/3] Trigger typeahead:opened and typeahead:closed. --- src/typeahead_view.js | 7 ++++++- test/playground.html | 7 ++++++- test/typeahead_view_spec.js | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/typeahead_view.js b/src/typeahead_view.js index b7eb10f3..2c47f628 100644 --- a/src/typeahead_view.js +++ b/src/typeahead_view.js @@ -80,7 +80,8 @@ var TypeaheadView = (function() { .on('cursorRemoved', this._updateHint) .on('suggestionsRendered', this._updateHint) .on('opened', this._updateHint) - .on('closed', this._clearHint); + .on('closed', this._clearHint) + .on('opened closed', this._propagateEvent); this.inputView = new InputView({ input: $input, hint: $hint }) .on('focused', this._openDropdown) @@ -261,6 +262,10 @@ var TypeaheadView = (function() { } }, + _propagateEvent: function(e) { + this.eventBus.trigger(e.type); + }, + // public methods // -------------- diff --git a/test/playground.html b/test/playground.html index 5fc45730..496c4183 100644 --- a/test/playground.html +++ b/test/playground.html @@ -101,7 +101,11 @@ "Wyoming" ] }) - .on('typeahead:selected', logToTextarea); + .on([ + 'typeahead:selected', + 'typeahead:opened', + 'typeahead:closed' + ].join(' '), logToTextarea); $('.bad-tokens').typeahead({ local: [ @@ -147,6 +151,7 @@ stringifiedArgs = JSON ? JSON.stringify(args) : ''; $textarea.val([val, type, stringifiedArgs, '\n'].join('\n')); + $textarea[0].scrollTop = $textarea[0].scrollHeight; } diff --git a/test/typeahead_view_spec.js b/test/typeahead_view_spec.js index 1a351003..730f9263 100644 --- a/test/typeahead_view_spec.js +++ b/test/typeahead_view_spec.js @@ -92,14 +92,32 @@ describe('TypeaheadView', function() { _updateHintSpecHelper('dropdownView', 'suggestionsRendered'); }); + describe('when dropdownView triggers opened', function() { + beforeEach(function() { + this.spy = spyOnEvent(this.$input, 'typeahead:opened'); + this.dropdownView.trigger('opened'); + }); + + // TODO: test _updateHint path + + it('should trigger typeahead:opened on the input', function() { + expect(this.spy).toHaveBeenTriggered(); + }); + }); + describe('when dropdownView triggers closed', function() { beforeEach(function() { + this.spy = spyOnEvent(this.$input, 'typeahead:closed'); this.dropdownView.trigger('closed'); }); it('should clear hint', function() { expect(this.inputView.setHintValue).toHaveBeenCalledWith(''); }); + + it('should trigger typeahead:closed on the input', function() { + expect(this.spy).toHaveBeenTriggered(); + }); }); // handlers triggered by inputView events From d789c4b2e8a05204270f5c1264b68c18f6ca85a5 Mon Sep 17 00:00:00 2001 From: Jake Harding Date: Tue, 12 Mar 2013 22:13:40 -0700 Subject: [PATCH 3/3] Trigger typeahead:initialized. --- src/dataset.js | 37 +++++++++++++++------ src/typeahead.js | 34 +++++++++++++------ src/typeahead_view.js | 4 +-- test/dataset_spec.js | 65 +++++++++++++++++++++++-------------- test/playground.html | 14 ++++---- test/typeahead_view_spec.js | 1 + 6 files changed, 103 insertions(+), 52 deletions(-) diff --git a/src/dataset.js b/src/dataset.js index 57d09f40..5fded1d0 100644 --- a/src/dataset.js +++ b/src/dataset.js @@ -10,13 +10,22 @@ var Dataset = (function() { utils.bindAll(this); if (o.template && !o.engine) { - throw new Error('no template engine specified'); + $.error('no template engine specified'); + } + + if (!o.local && !o.prefetch && !o.remote) { + $.error('one of local, prefetch, or remote is requried'); } this.name = o.name; this.limit = o.limit || 5; this.template = compileTemplate(o.template, o.engine); + // used in #initialize + this.local = o.local; + this.prefetch = o.prefetch; + this.remote = o.remote; + this.keys = { version: 'version', protocol: 'protocol', @@ -40,6 +49,7 @@ var Dataset = (function() { _loadPrefetchData: function(o) { var that = this, + deferred, version = this.storage.get(this.keys.version), protocol = this.storage.get(this.keys.protocol), itemHash = this.storage.get(this.keys.itemHash), @@ -55,12 +65,16 @@ var Dataset = (function() { itemHash: itemHash, adjacencyList: adjacencyList }); + + deferred = $.Deferred().resolve(); } else { - $.getJSON(o.url).done(processPrefetchData); + deferred = $.getJSON(o.url).done(processPrefetchData); } + return deferred; + function processPrefetchData(data) { var filteredData = o.filter ? o.filter(data) : data, processedData = that._processData(filteredData), @@ -256,17 +270,20 @@ var Dataset = (function() { // the contents of this function are broken out of the constructor // to help improve the testability of datasets - initialize: function(o) { - if (!o.local && !o.prefetch && !o.remote) { - throw new Error('one of local, prefetch, or remote is requried'); - } + initialize: function() { + var deferred; + + this.local && this._processLocalData(this.local); + this.transport = this.remote ? new Transport(this.remote) : null; - this.transport = o.remote ? new Transport(o.remote) : null; + deferred = this.prefetch ? + this._loadPrefetchData(this.prefetch) : + $.Deferred().resolve(); - o.local && this._processLocalData(o.local); - o.prefetch && this._loadPrefetchData(o.prefetch); + this.local = this.prefetch = this.remote = null; + this.initialize = function() { return deferred; }; - return this; + return deferred; }, getSuggestions: function(query, callback) { diff --git a/src/typeahead.js b/src/typeahead.js index 66aff87b..062f4a9e 100644 --- a/src/typeahead.js +++ b/src/typeahead.js @@ -5,7 +5,7 @@ */ (function() { - var datasetCache = {}, methods; + var datasetCache = {}, viewKey = 'ttView', methods; methods = { initialize: function(datasetDefs) { @@ -14,11 +14,11 @@ datasetDefs = utils.isArray(datasetDefs) ? datasetDefs : [datasetDefs]; if (this.length === 0) { - throw new Error('typeahead initialized without DOM element'); + $.error('typeahead initialized without DOM element'); } if (datasetDefs.length === 0) { - throw new Error('no datasets provided'); + $.error('no datasets provided'); } datasets = utils.map(datasetDefs, function(o) { @@ -26,25 +26,39 @@ return datasetCache[o.name] ? datasetCache[o.name] : - datasetCache[o.name] = new Dataset(o).initialize(o); + datasetCache[o.name] = new Dataset(o); }); - return this.each(function() { + return this.each(initialize); + + function initialize() { var $input = $(this), - view = new TypeaheadView({ input: $input, datasets: datasets }); + deferreds, + eventBus = new EventBus({ el: $input }); - $input.data('ttView', view); - }); + deferreds = utils.map(datasets, function(dataset) { + return dataset.initialize(); + }); + + $input.data(viewKey, new TypeaheadView({ + input: $input, + eventBus: eventBus = new EventBus({ el: $input }), + datasets: datasets + })); + + $.when.apply($, deferreds) + .always(function() { eventBus.trigger('initialized'); }); + } }, destroy: function() { this.each(function() { var $this = $(this), - view = $this.data('ttView'); + view = $this.data(viewKey); if (view) { view.destroy(); - $this.removeData('ttView'); + $this.removeData(viewKey); } }); } diff --git a/src/typeahead_view.js b/src/typeahead_view.js index 2c47f628..d9eb0c27 100644 --- a/src/typeahead_view.js +++ b/src/typeahead_view.js @@ -66,12 +66,12 @@ var TypeaheadView = (function() { this.datasets = o.datasets; this.dir = null; + this.eventBus = o.eventBus; + $menu = this.$node.find('.tt-dropdown-menu'); $input = this.$node.find('.tt-query'); $hint = this.$node.find('.tt-hint'); - this.eventBus = new EventBus({ el: $input }); - this.dropdownView = new DropdownView({ menu: $menu }) .on('suggestionSelected', this._handleSelection) .on('cursorMoved', this._clearHint) diff --git a/test/dataset_spec.js b/test/dataset_spec.js index 7f341a9b..5208203f 100644 --- a/test/dataset_spec.js +++ b/test/dataset_spec.js @@ -70,6 +70,16 @@ describe('Dataset', function() { }); }); + describe('when called without local, prefetch, or remote', function() { + beforeEach(function() { + this.fn = function() { this.dataset = new Dataset(); }; + }); + + it('should throw an error', function() { + expect(this.fn).toThrow(); + }); + }); + describe('when called with no template', function() { beforeEach(function() { this.dataset = new Dataset({ local: fixtureData }); @@ -100,23 +110,22 @@ describe('Dataset', function() { }); describe('#initialize', function() { - beforeEach(function() { - this.dataset = new Dataset({ name: '#initialize' }); - }); + it('should return Deferred instance', function() { + var returnVal; - describe('when called without local, prefetch, or remote', function() { - beforeEach(function() { - this.fn = function() { this.dataset.initialize({}); }; - }); + this.dataset = new Dataset({ local: fixtureData }); + returnVal = this.dataset.initialize(); - it('should throw an error', function() { - expect(this.fn).toThrow(); - }); + // eh, have to rely on duck typing unfortunately + expect(returnVal.fail).toBeDefined(); + expect(returnVal.done).toBeDefined(); + expect(returnVal.always).toBeDefined(); }); describe('when called with local', function() { beforeEach(function() { - this.dataset.initialize({ local: fixtureData }); + this.dataset = new Dataset({ local: fixtureData }); + this.dataset.initialize(); }); it('should process and merge the data', function() { @@ -128,8 +137,9 @@ describe('Dataset', function() { describe('when called with prefetch', function() { describe('if data is available in storage', function() { beforeEach(function() { + this.dataset = new Dataset({ prefetch: '/prefetch.json' }); this.dataset.storage.get.andCallFake(mockStorageFns.getHit); - this.dataset.initialize({ prefetch: '/prefetch.json' }); + this.dataset.initialize(); }); it('should not make ajax request', function() { @@ -146,10 +156,6 @@ describe('Dataset', function() { // default ttl var ttl = 24 * 60 * 60 * 1000; - beforeEach(function() { - this.dataset.storage.get.andCallFake(mockStorageFns.getMiss); - }); - describe('if filter was passed in', function() { var filteredAdjacencyList = { f: ['filter'] }, filteredItemHash = { @@ -157,13 +163,16 @@ describe('Dataset', function() { }; beforeEach(function() { - this.dataset.initialize({ + this.dataset = new Dataset({ prefetch: { url: '/prefetch.json', filter: function(data) { return ['filter']; } } }); + this.dataset.storage.get.andCallFake(mockStorageFns.getMiss); + this.dataset.initialize(); + this.request = mostRecentAjaxRequest(); this.request.response(prefetchResp); }); @@ -194,7 +203,11 @@ describe('Dataset', function() { describe('if filter was not passed in', function() { beforeEach(function() { - this.dataset.initialize({ prefetch: '/prefetch.json' }); + this.dataset = new Dataset({ prefetch: '/prefetch.json' }); + + this.dataset.storage.get.andCallFake(mockStorageFns.getMiss); + + this.dataset.initialize(); this.request = mostRecentAjaxRequest(); this.request.response(prefetchResp); @@ -228,7 +241,8 @@ describe('Dataset', function() { describe('when called with remote', function() { beforeEach(function() { - this.dataset.initialize({ remote: '/remote' }); + this.dataset = new Dataset({ remote: '/remote' }); + this.dataset.initialize(); }); it('should initialize the transport', function() { @@ -239,7 +253,8 @@ describe('Dataset', function() { describe('Datasource options', function() { beforeEach(function() { - this.dataset = new Dataset({}).initialize({ local: fixtureData }); + this.dataset = new Dataset({ local: fixtureData }); + this.dataset.initialize(); }); it('allow for a custom matching function to be defined', function() { @@ -272,8 +287,8 @@ describe('Dataset', function() { describe('Matching, ranking, combining, returning results', function() { beforeEach(function() { - this.dataset = new Dataset({}) - .initialize({ local: fixtureData, remote: '/remote' }); + this.dataset = new Dataset({ local: fixtureData, remote: '/remote' }); + this.dataset.initialize(); }); it('network requests are not triggered with enough local results', function() { @@ -362,7 +377,8 @@ describe('Dataset', function() { var fixtureData = ['course-106', 'user_name', 'One-Two', 'two three']; beforeEach(function() { - this.dataset = new Dataset({}).initialize({ local: fixtureData }); + this.dataset = new Dataset({ local: fixtureData }); + this.dataset.initialize(); }); it('normalizes capitalization to match items', function() { @@ -407,7 +423,8 @@ describe('Dataset', function() { var fixtureData = [{ value: 'course-106', tokens: ['course-106'] }]; beforeEach(function() { - this.dataset = new Dataset({}).initialize({ local: fixtureData }); + this.dataset = new Dataset({ local: fixtureData }); + this.dataset.initialize(); }); it('matches items with dashes', function() { diff --git a/test/playground.html b/test/playground.html index 496c4183..5fb47880 100644 --- a/test/playground.html +++ b/test/playground.html @@ -47,6 +47,13 @@