From 6551420e1ae0e91201de72e862e918dd3c97ab43 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 30 Sep 2017 20:27:26 +0900 Subject: move messages to content --- src/pages/completion.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/pages/completion.js (limited to 'src/pages/completion.js') diff --git a/src/pages/completion.js b/src/pages/completion.js new file mode 100644 index 0000000..4c69afb --- /dev/null +++ b/src/pages/completion.js @@ -0,0 +1,27 @@ +export default class Completion { + constructor(completions) { + if (typeof completions.length !== 'number') { + throw new TypeError('completions does not have a length in number'); + } + this.completions = completions; + this.index = 0; + } + + prev() { + let length = this.completions.length; + if (length === 0) { + return null; + } + this.index = (this.index + length - 1) % length; + return this.completions[this.index]; + } + + next() { + if (this.completions.length === 0) { + return null; + } + let item = this.completions[this.index]; + this.index = (this.index + 1) % this.completions.length; + return item; + } +} -- cgit v1.2.3