From 444f6caf1324f2fc3b4554efebb600fa41392471 Mon Sep 17 00:00:00 2001 From: steelbrain Date: Mon, 4 Jan 2016 00:05:03 -0700 Subject: [PATCH 1/2] :fire: Remove createElement API --- README.md | 8 -------- lib/helpers.js | 32 +++----------------------------- src/helpers.js | 28 +++------------------------- 3 files changed, 6 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index 8b6e040..3698735 100644 --- a/README.md +++ b/README.md @@ -20,17 +20,9 @@ class Helpers{ static findCachedAsync(directory: Strng, names: String | Array): Promise static tempFile(fileName:String, fileContents:String, Callback:Function):Promise static tempFiles(filesNames:Array<{name: String, contents: String}>, callback:Function):Promise - static createElement(tagName: string): HTMLElement } ``` -#### Explanation for createElement - -Linter accepts `HTMLElement`s in the `html` message property. To show the same message on more -than one DOM Elements, it clones the element. It's a limitation of HTMLElements that they -lose all the events on clone. If you create your element using `Helpers.createElement` however -It'll make sure the children inherit the events from the parent. - #### License This project is licensed under the terms of MIT License, see the LICENSE file for more info diff --git a/lib/helpers.js b/lib/helpers.js index 922aa73..2a1093a 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -8,7 +8,6 @@ exports.FindCache = undefined; exports.exec = exec; exports.execNode = execNode; exports.rangeFromLineNumber = rangeFromLineNumber; -exports.createElement = createElement; exports.findAsync = findAsync; exports.findCachedAsync = findCachedAsync; exports.find = find; @@ -36,7 +35,6 @@ var _consistentPath = require('consistent-path'); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } let XRegExp = null; -const EventsCache = new WeakMap(); const FindCache = exports.FindCache = new Map(); // TODO: Remove this when electron upgrades node @@ -178,32 +176,6 @@ function rangeFromLineNumber(textEditor, lineNumber, colStart) { return [[lineNumber, colStart], [lineNumber, lineLength]]; } -function createElement(name) { - if (typeof name !== 'string') { - throw new Error('Invalid or no `Element name` provided'); - } - - const element = document.createElement(name); - - element.addEventListener = function (name, callback) { - EventsCache.get(element).push({ name: name, callback: callback }); - Element.prototype.addEventListener.call(this, name, callback); - }; - element.cloneNode = function (deep) { - const newElement = Element.prototype.cloneNode.call(this, deep); - EventsCache.get(element).forEach(function (_ref2) { - let name = _ref2.name; - let callback = _ref2.callback; - - newElement.addEventListener(name, callback); - }); - return newElement; - }; - - EventsCache.set(element, []); - return element; -} - function findAsync(directory, name) { validate_find(directory, name); const names = name instanceof Array ? name : [name]; @@ -242,12 +214,13 @@ function findAsync(directory, name) { } function findCachedAsync(directory, name) { + validate_find(directory, name); const names = name instanceof Array ? name : [name]; const cacheKey = directory + ':' + names.join(','); if (FindCache.has(cacheKey)) { const cachedFilePath = FindCache.get(cacheKey); - return new Promise(function (resolve, reject) { + return new Promise(function (resolve) { FS.access(cachedFilePath, FS.R_OK, function (error) { if (error) { FindCache.delete(cacheKey); @@ -288,6 +261,7 @@ function find(directory, name) { } function findCached(directory, name) { + validate_find(directory, name); const names = name instanceof Array ? name : [name]; const cacheKey = directory + ':' + names.join(','); diff --git a/src/helpers.js b/src/helpers.js index a4efe1c..e48218e 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -7,7 +7,6 @@ import * as TMP from 'tmp' import {getPath} from 'consistent-path' let XRegExp = null -const EventsCache = new WeakMap() export const FindCache = new Map() // TODO: Remove this when electron upgrades node @@ -145,29 +144,6 @@ export function rangeFromLineNumber(textEditor, lineNumber, colStart) { ] } -export function createElement(name) { - if (typeof name !== 'string') { - throw new Error('Invalid or no `Element name` provided') - } - - const element = document.createElement(name) - - element.addEventListener = function(name, callback) { - EventsCache.get(element).push({name, callback}) - Element.prototype.addEventListener.call(this, name, callback) - } - element.cloneNode = function(deep) { - const newElement = Element.prototype.cloneNode.call(this, deep) - EventsCache.get(element).forEach(function({name, callback}) { - newElement.addEventListener(name, callback) - }) - return newElement - } - - EventsCache.set(element, []) - return element -} - export function findAsync(directory, name) { validate_find(directory, name) const names = name instanceof Array ? name : [name] @@ -206,12 +182,13 @@ export function findAsync(directory, name) { } export function findCachedAsync(directory, name) { + validate_find(directory, name) const names = name instanceof Array ? name : [name] const cacheKey = directory + ':' + names.join(',') if (FindCache.has(cacheKey)) { const cachedFilePath = FindCache.get(cacheKey) - return new Promise(function(resolve, reject) { + return new Promise(function(resolve) { FS.access(cachedFilePath, FS.R_OK, function(error) { if (error) { FindCache.delete(cacheKey) @@ -252,6 +229,7 @@ export function find(directory, name) { } export function findCached(directory, name) { + validate_find(directory, name) const names = name instanceof Array ? name : [name] const cacheKey = directory + ':' + names.join(',') From dfaf076bf26edee17bd9384254f9936dcf40ea89 Mon Sep 17 00:00:00 2001 From: steelbrain Date: Mon, 4 Jan 2016 00:06:08 -0700 Subject: [PATCH 2/2] :fire: Remove createElement specifications --- spec/helper-spec.coffee | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/spec/helper-spec.coffee b/spec/helper-spec.coffee index c89606a..4450580 100644 --- a/spec/helper-spec.coffee +++ b/spec/helper-spec.coffee @@ -271,25 +271,3 @@ describe 'linter helpers', -> return filePaths ).then (result) -> expect(result.length).toBe(2) - - describe '::createElement', -> - it 'works', -> - clicked = false - clickListener = -> clicked = true - - el = helpers.createElement('div') - el.innerHTML = 'Some HTML' - expect(el.innerHTML).toBe('Some HTML') - el.appendChild(document.createElement('div')) - expect(el.children.length).toBe(1) - - el.addEventListener('click', clickListener) - - expect(clicked).toBe(false) - el.dispatchEvent(new MouseEvent('click')) - expect(clicked).toBe(true) - - clicked = false - clonedEl = el.cloneNode(true) - clonedEl.dispatchEvent(new MouseEvent('click')) - expect(clicked).toBe(true)