cleanup code

This commit is contained in:
pypy
2020-02-25 23:07:30 +09:00
parent 5a3068ccbc
commit 47bc480d17
+14 -16
View File
@@ -21,8 +21,6 @@ CefSharp.BindObjectAsync(
} }
}); });
var isObject = (arg) => arg === Object(arg);
VRCXStorage.GetBool = function (key) { VRCXStorage.GetBool = function (key) {
return this.Get(key) === 'true'; return this.Get(key) === 'true';
}; };
@@ -68,7 +66,7 @@ CefSharp.BindObjectAsync(
VRCXStorage.GetObject = function (key) { VRCXStorage.GetObject = function (key) {
try { try {
var object = JSON.parse(this.Get(key)); var object = JSON.parse(this.Get(key));
if (isObject(object)) { if (object === Object(object)) {
return object; return object;
} }
} catch (err) { } catch (err) {
@@ -274,7 +272,7 @@ CefSharp.BindObjectAsync(
var isGetRequest = init.method === 'GET'; var isGetRequest = init.method === 'GET';
if (isGetRequest) { if (isGetRequest) {
// transform body to url // transform body to url
if (isObject(params)) { if (params === Object(params)) {
var url = new URL(resource); var url = new URL(resource);
var { searchParams } = url; var { searchParams } = url;
for (var key in params) { for (var key in params) {
@@ -292,7 +290,7 @@ CefSharp.BindObjectAsync(
'Content-Type': 'application/json;charset=utf-8', 'Content-Type': 'application/json;charset=utf-8',
...init.headers ...init.headers
}; };
init.body = isObject(params) init.body = params === Object(params)
? JSON.stringify(params) ? JSON.stringify(params)
: '{}'; : '{}';
} }
@@ -305,7 +303,7 @@ CefSharp.BindObjectAsync(
this.$throw(res.status); this.$throw(res.status);
}).then((json) => { }).then((json) => {
if (res.ok) { if (res.ok) {
if (isObject(json.success)) { if (json.success === Object(json.success)) {
new Noty({ new Noty({
type: 'success', type: 'success',
text: escapeTag(json.success.message) text: escapeTag(json.success.message)
@@ -313,8 +311,8 @@ CefSharp.BindObjectAsync(
} }
return json; return json;
} }
if (isObject(json)) { if (json === Object(json)) {
if (isObject(json.error)) { if (json.error === Object(json.error)) {
this.$throw( this.$throw(
json.error.status_code || res.status, json.error.status_code || res.status,
json.error.message, json.error.message,
@@ -990,7 +988,7 @@ CefSharp.BindObjectAsync(
} else { } else {
var props = {}; var props = {};
for (var prop in ref) { for (var prop in ref) {
if (isObject(ref[prop]) === false) { if (ref[prop] !== Object(ref[prop])) {
props[prop] = true; props[prop] = true;
} }
} }
@@ -1001,7 +999,7 @@ CefSharp.BindObjectAsync(
} }
this.applyUserTrustLevel(ref); this.applyUserTrustLevel(ref);
for (var prop in ref) { for (var prop in ref) {
if (isObject(ref[prop]) === false) { if (ref[prop] !== Object(ref[prop])) {
props[prop] = true; props[prop] = true;
} }
} }
@@ -1655,12 +1653,12 @@ CefSharp.BindObjectAsync(
Object.assign(ref, json); Object.assign(ref, json);
ref.$isExpired = false; ref.$isExpired = false;
} }
if (isObject(ref.details) === false) { if (ref.details !== Object(ref.details)) {
var details = {}; var details = {};
if (ref.details !== '{}') { if (ref.details !== '{}') {
try { try {
var object = JSON.parse(ref.details); var object = JSON.parse(ref.details);
if (isObject(object)) { if (object === Object(object)) {
details = object; details = object;
} }
} catch (err) { } catch (err) {
@@ -2830,7 +2828,7 @@ CefSharp.BindObjectAsync(
break; break;
case 'user-location': case 'user-location':
if (isObject(content.world)) { if (content.world === Object(content.world)) {
this.$emit('WORLD', { this.$emit('WORLD', {
json: content.world, json: content.world,
params: { params: {
@@ -2936,7 +2934,7 @@ CefSharp.BindObjectAsync(
if (Array.isArray(value)) { if (Array.isArray(value)) {
node.push({ node.push({
children: value.map((val, idx) => { children: value.map((val, idx) => {
if (isObject(val)) { if (val === Object(val)) {
return { return {
children: buildTreeData(val), children: buildTreeData(val),
key: idx key: idx
@@ -2949,7 +2947,7 @@ CefSharp.BindObjectAsync(
}), }),
key key
}); });
} else if (isObject(value)) { } else if (value === Object(value)) {
node.push({ node.push({
children: buildTreeData(value), children: buildTreeData(value),
key key
@@ -3060,7 +3058,7 @@ CefSharp.BindObjectAsync(
$app.methods.checkAppVersion = function () { $app.methods.checkAppVersion = function () {
var url = 'https://api.github.com/repos/pypy-vrc/VRCX/releases/latest'; var url = 'https://api.github.com/repos/pypy-vrc/VRCX/releases/latest';
fetch(url).then((res) => res.json()).then((json) => { fetch(url).then((res) => res.json()).then((json) => {
if (isObject(json) && if (json === Object(json) &&
json.name && json.name &&
json.published_at) { json.published_at) {
this.latestAppVersion = `${json.name} (${formatDate(json.published_at, 'YYYY-MM-DD HH24:MI:SS')})`; this.latestAppVersion = `${json.name} (${formatDate(json.published_at, 'YYYY-MM-DD HH24:MI:SS')})`;