-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from doughsay/fix-text-search
Fix exceptions when unknown search results come from server.
- Loading branch information
Showing
10 changed files
with
89 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import ko from 'knockout' | ||
|
||
export default class SearchResult { | ||
constructor (data) { | ||
this.data = data | ||
this.objectId = data.objectId | ||
this.active = ko.observable(false) | ||
this.name = ko.computed(this.computeName.bind(this)) | ||
} | ||
|
||
static newFromResult (result) { | ||
if (result.function) { | ||
return new FunctionSearchResult(result) | ||
} else if (result.verb) { | ||
return new VerbSearchResult(result) | ||
} | ||
|
||
return null | ||
} | ||
|
||
computeName () { | ||
throw new Error('Must be subclassed.') | ||
} | ||
|
||
openEditor () { | ||
throw new Error('Must be subclassed.') | ||
} | ||
} | ||
|
||
class FunctionSearchResult extends SearchResult { | ||
computeName () { | ||
return `${this.objectId}.${this.data.function}` | ||
} | ||
|
||
openEditor (socket, tabsViewModel) { | ||
const params = { objectId: this.objectId, name: this.data.function } | ||
socket.emit('get-function', params, data => { | ||
tabsViewModel.newEditFunctionTab(socket, data) | ||
}) | ||
} | ||
} | ||
|
||
class VerbSearchResult extends SearchResult { | ||
computeName () { | ||
return `${this.objectId}.${this.data.verb}` | ||
} | ||
|
||
openEditor (socket, tabsViewModel) { | ||
const params = { objectId: this.objectId, name: this.data.verb } | ||
socket.emit('get-verb', params, data => { | ||
tabsViewModel.newEditVerbTab(socket, data) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import test from 'ava' | ||
import SearchResult from '../../src/lib/search-result' | ||
|
||
test('SearchResult: newFromResult works for function result', t => { | ||
const result = { objectId: 'foo', function: 'bar' } | ||
const searchResult = SearchResult.newFromResult(result) | ||
|
||
t.truthy(searchResult) | ||
}) | ||
|
||
test('SearchResult: newFromResult works for verb result', t => { | ||
const result = { objectId: 'foo', verb: 'bar' } | ||
const searchResult = SearchResult.newFromResult(result) | ||
|
||
t.truthy(searchResult) | ||
}) | ||
|
||
test('SearchResult: newFromResult doesn\'t work for text result', t => { | ||
const result = { objectId: 'foo', text: 'bar' } | ||
const searchResult = SearchResult.newFromResult(result) | ||
|
||
t.falsy(searchResult) | ||
}) |