Skip to content

Commit

Permalink
Update DictionaryDataUtil to be able to be used in a sandbox frame (F…
Browse files Browse the repository at this point in the history
  • Loading branch information
toasted-nutbread authored Jan 8, 2021
1 parent 3760b22 commit 7d706df
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
6 changes: 4 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
{
"files": [
"ext/mixed/js/core.js",
"ext/bg/js/template-renderer.js"
"ext/bg/js/template-renderer.js",
"ext/mixed/js/dictionary-data-util.js"
],
"env": {
"webextensions": false
Expand All @@ -94,7 +95,8 @@
"files": ["ext/**/*.js"],
"excludedFiles": [
"ext/mixed/js/core.js",
"ext/bg/js/template-renderer.js"
"ext/bg/js/template-renderer.js",
"ext/mixed/js/dictionary-data-util.js"
],
"globals": {
"errorToJson": "readonly",
Expand Down
30 changes: 28 additions & 2 deletions ext/mixed/js/dictionary-data-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class DictionaryDataUtil {
const exclusiveExpressions = [];
const exclusiveReadings = [];
const resultExpressions = result.expressions;
if (!areSetsEqual(resultExpressions, allExpressions)) {
exclusiveExpressions.push(...getSetIntersection(resultExpressions, allExpressions));
if (!this._areSetsEqual(resultExpressions, allExpressions)) {
exclusiveExpressions.push(...this._getSetIntersection(resultExpressions, allExpressions));
}
if (multipleReadings) {
exclusiveReadings.push(result.reading);
Expand All @@ -71,6 +71,8 @@ class DictionaryDataUtil {
return results2;
}

// Private

static _findExistingPitchAccentInfo(reading, position, tags, pitchAccentInfoList) {
for (const pitchInfo of pitchAccentInfoList) {
if (
Expand Down Expand Up @@ -98,4 +100,28 @@ class DictionaryDataUtil {

return true;
}

static _areSetsEqual(set1, set2) {
if (set1.size !== set2.size) {
return false;
}

for (const value of set1) {
if (!set2.has(value)) {
return false;
}
}

return true;
}

static _getSetIntersection(set1, set2) {
const result = [];
for (const value of set1) {
if (set2.has(value)) {
result.push(value);
}
}
return result;
}
}

0 comments on commit 7d706df

Please sign in to comment.