Skip to content

Commit

Permalink
added EVENTS endpoint that emits a 'ready' event immediately after in…
Browse files Browse the repository at this point in the history
…itialisation
  • Loading branch information
fergiemcdowall committed Aug 27, 2024
1 parent dadba8e commit c7d852a
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion dist/search-index-5.0.0.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/search-index-esm-5.0.0.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/search-index.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "search-index",
"version": "5.0.0",
"version": "5.1.0",
"description": "A network resilient, persistent full-text search library for the browser and Node.js",
"keywords": [
"search",
Expand Down Expand Up @@ -75,7 +75,7 @@
"dependencies": {
"browser-level": "^1.0.1",
"classic-level": "^1.4.1",
"fergies-inverted-index": "13.0.0",
"fergies-inverted-index": "13.1.0",
"lru-cache": "11.0.0",
"ngraminator": "3.0.2",
"p-queue": "8.0.1",
Expand Down
5 changes: 5 additions & 0 deletions src/SearchIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class SearchIndex {
tokenizer: defaultPipeline,
...ops
}

this.INDEX = new InvertedIndex({
...ops,
// isLeaf must be like so and is not a user defined option
Expand All @@ -65,6 +66,10 @@ export class SearchIndex {
item === null
)
})

// event bus
this.EVENTS = this.INDEX.EVENTS

// Now that constructor is not async- not sure where this should be called...
this._CACHE = new LRUCache({ max: ops.cacheLength })
this.r = new Reader(ops, this._CACHE, this.INDEX)
Expand Down
12 changes: 12 additions & 0 deletions test/src/EVENT-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import test from 'tape'
import { SearchIndex } from 'search-index'

const sandbox = 'test/sandbox/'
const indexName = sandbox + 'EVENTS'
const global = {}

test('create a search index and listen to the "ready" event', t => {
t.plan(2)
t.ok((global[indexName] = new SearchIndex({ name: indexName })), !undefined)
global[indexName].EVENTS.on('ready', () => t.pass('ready event emitted'))
})

0 comments on commit c7d852a

Please sign in to comment.