Skip to content

Commit

Permalink
🔥 Remove caching
Browse files Browse the repository at this point in the history
  • Loading branch information
Steel Brain committed Jul 27, 2017
1 parent d6e645a commit 2724d53
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 33 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
#### 1.1.5

- Remove cache introduced in v1.1.3

#### 1.1.4

- Fix a regression from last release
Expand Down
36 changes: 3 additions & 33 deletions lib/main.js
Expand Up @@ -6,21 +6,17 @@ import Commands from './commands'
import ListView from './view-list'
import ProvidersList from './providers-list'
import ProvidersHighlight from './providers-highlight'
import type { ListProvider, HighlightProvider, HighlightItem, ListItem } from './types'
import type { ListProvider, HighlightProvider } from './types'

export default class Intentions {
active: ?Disposable;
commands: Commands;
listCache: WeakMap<Object, { text: string, results: Array<ListItem> }>
highlightCache: WeakMap<Object, { text: string, results: Array<HighlightItem> }>
providersList: ProvidersList;
providersHighlight: ProvidersHighlight;
subscriptions: CompositeDisposable;
constructor() {
this.active = null
this.commands = new Commands()
this.listCache = new WeakMap()
this.highlightCache = new WeakMap()
this.providersList = new ProvidersList()
this.providersHighlight = new ProvidersHighlight()
this.subscriptions = new CompositeDisposable()
Expand All @@ -31,20 +27,7 @@ export default class Intentions {

// eslint-disable-next-line arrow-parens
this.commands.onListShow(async (textEditor) => {
let results
const cached = this.listCache.get(textEditor)
const editorText = textEditor.getText()
if (cached && cached.text === editorText) {
results = cached.results
} else {
results = await this.providersList.trigger(textEditor)
if (results.length) {
this.listCache.set(textEditor, {
text: editorText,
results,
})
}
}
const results = await this.providersList.trigger(textEditor)
if (!results.length) {
return false
}
Expand Down Expand Up @@ -78,20 +61,7 @@ export default class Intentions {
})
// eslint-disable-next-line arrow-parens
this.commands.onHighlightsShow(async (textEditor) => {
let results
const cached = this.highlightCache.get(textEditor)
const editorText = textEditor.getText()
if (cached && cached.text === editorText) {
results = cached.results
} else {
results = await this.providersHighlight.trigger(textEditor)
if (results.length) {
this.highlightCache.set(textEditor, {
text: editorText,
results,
})
}
}
const results = await this.providersHighlight.trigger(textEditor)
if (!results.length) {
return false
}
Expand Down

0 comments on commit 2724d53

Please sign in to comment.