Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.

Commit 758ea12

Browse files
committed
FIX: isset function usage & abstract class constructors
1 parent 0b3de75 commit 758ea12

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

lib/icon-helper.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/snippet-injector.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ export default {
1313

1414
activate(state) {
1515
this.storage = new Storage({dir: '/storage/snippet-injector/snippets/'});
16-
console.warn(this.storage.storageDir);
17-
console.warn(this.storage.dir);
1816
this.storage.migrate();
1917

20-
// Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
18+
new IconHelper();
19+
2120
this.subscriptions = new CompositeDisposable();
22-
// Register command that toggles this view
2321
this.subscriptions.add(atom.commands.add('atom-workspace', {
2422
'snippet-injector:create': () => this.create(),
2523
'snippet-injector:insert': () => this.insert(),
@@ -44,7 +42,7 @@ export default {
4442
var uid = Util.generateUID({
4543
unique: true,
4644
tester: storage.testFile,
47-
timeout: 25,
45+
timeout: 100,
4846
length: 20,
4947
prefix: 'sn',
5048
insertstring: 'SNIPPET'
@@ -54,7 +52,7 @@ export default {
5452
btnconfirm: 'Save snippet',
5553
btncancel: 'Cancel'
5654
},function(text){
57-
if(text !== null && text !== undefined) {
55+
if(Util.isset(text,'string')) {
5856
var result = storage.store(new Snippet({
5957
title: text,
6058
tags: new Array(),
@@ -91,7 +89,7 @@ export default {
9189
nothingfound: 'No Snippets found that match you search.',
9290
icons: icons
9391
},function(element) {
94-
if(element !== null && element !== undefined) {
92+
if(Util.isset(element,'string')) {
9593
var snippet = new Snippet(JSON.parse(storage.retrieveFile(element)));
9694
atom.workspace.getActiveTextEditor().insertText(snippet.getContent(),{
9795
select: true,
@@ -128,7 +126,7 @@ export default {
128126
suremsg: 'Are you sure?',
129127
items: items
130128
},function(element) {
131-
if(element !== null && element !== undefined) {
129+
if(Util.isset(element,'string')) {
132130
var snippet = new Snippet(JSON.parse(storage.retrieveFile(element)));
133131
if(storage.deleteFile(snippet.getUID())) {
134132
atom.notifications.addSuccess('Snippet \''+snippet.getTitle()+'\' was successfully deleted.', null);

lib/storage.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import { dirname } from 'path';
44
import Snippet from './snippet.js';
55
import Util from './util.js';
66
const fs = require('fs');
7-
const os = require('os');
7+
// const os = require('os');
88

99
export default class Storage {
1010

1111
dir = '';
1212
storageDir = dirname(atom.config.getUserConfigPath());
1313

1414
constructor(state) {
15-
if(state !== undefined && state !== null && typeof state === 'object') {
16-
if(state.dir !== undefined && state.dir !== null && typeof state.dir === 'string') {
15+
if(Util.isset(state,'object')) {
16+
if(Util.isset(state.dir,'string')) {
1717
this.init(state.dir);
1818
}
1919
}
@@ -44,7 +44,7 @@ export default class Storage {
4444
var temp = divider;
4545

4646
directory.split(divider).forEach(function(currentValue,index) {
47-
if(currentValue !== "" && currentValue !== " " && currentValue !== null && currentValue !== undefined) {
47+
if(currentValue !== "" && currentValue !== " " && Util.isset(currentValue,'string')) {
4848
temp += currentValue+divider;
4949
try {
5050
fs.statSync(store+temp);
@@ -57,7 +57,7 @@ export default class Storage {
5757
}
5858

5959
store(snippet) {
60-
if(snippet !== null && snippet !== undefined && snippet instanceof Snippet) {
60+
if(Util.isset(snippet,Snippet)) {
6161
fs.writeFileSync(this.storageDir+this.dir+snippet.getUID().split(' ').join('-')+'.json',JSON.stringify(snippet));
6262
return fs.existsSync(this.storageDir+this.dir+snippet.getUID().split(' ').join('-')+'.json');
6363
} else {
@@ -133,7 +133,7 @@ export default class Storage {
133133
snippet.setUID(Util.generateUID({
134134
unique: true,
135135
tester: _this.testFile,
136-
timeout: 25,
136+
timeout: 100,
137137
length: 20,
138138
prefix: 'sn',
139139
insertstring: 'SNIPPET'

lib/util.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const $ = require('jquery');
99
export default class Util {
1010

1111
constructor(state) {
12-
if(new.target === Node) throw TypeError("Cannot instantiate abstract class Util.");
12+
if(new.target === Util) throw TypeError("Cannot instantiate abstract class Util.");
1313
}
1414

1515
// Returns an object that can be retrieved when package is activated
@@ -342,7 +342,7 @@ export default class Util {
342342
patch: parseInt(vers2.split('.')[2])
343343
};
344344
console.log(versionB);
345-
345+
346346
if(versionA.major > versionB.major) {
347347
return vers1;
348348
} else if(versionB.major > versionA.major) {
@@ -368,6 +368,6 @@ export default class Util {
368368
}
369369

370370
static isset(attr,type) {
371-
return (attr !== null && attr !== undefined && typeof attr === type);
371+
return (attr !== null && attr !== undefined && (typeof attr === type || attr instanceof type));
372372
}
373373
}

0 commit comments

Comments
 (0)