Skip to content

Commit

Permalink
Fix Ember.typeof replace with custom typeof (emberjs#1052)
Browse files Browse the repository at this point in the history
* replace Ember.typeOf with own simple typeof

* Update mixin.scss

* fix comments

* use Object.prototype

* fix quotes

* detect asyncfunction as function

* fix

* fix

* last fix
  • Loading branch information
patricklx authored and nummi committed Apr 1, 2020
1 parent 8fde5a4 commit 8d05d55
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 25 deletions.
9 changes: 4 additions & 5 deletions app/components/object-inspector/property.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export default Component.extend({

isObject: equal('valueType', 'type-object'),

isInstance: equal('valueType', 'type-instance'),

isComputedProperty: alias('model.isComputed'),

isFunction: equal('valueType', 'type-function'),
isFunction: computed('valueType', function () {
return this.valueType === 'type-function' || this.valueType === 'type-asyncfunction';
}),

isArray: equal('valueType', 'type-array'),

Expand Down Expand Up @@ -81,8 +81,7 @@ export default Component.extend({
}),

canDig() {
return this.isInstance
|| this.isObject
return this.isObject
|| this.isEmberObject
|| this.isArray
},
Expand Down
2 changes: 1 addition & 1 deletion app/components/object-inspector/sort-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default Component.extend({
sorted: sort('props', 'sortProperties'),

props: map('properties', function (p) {
set(p, 'isFunction', p.value.type === 'type-function');
set(p, 'isFunction', p.value.type === 'type-function' || p.value.type === 'type-asyncfunction');
if (p.name == parseInt(p.name)) {
set(p, 'name', parseInt(p.name));
}
Expand Down
1 change: 0 additions & 1 deletion app/styles/mixin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ $mixin-left-padding: 22px;

.mixin__property .type-ember-object,
.mixin__property .type-object,
.mixin__property .type-instance,
.mixin__property .type-array {
cursor: pointer;
}
Expand Down
3 changes: 2 additions & 1 deletion ember_debug/adapters/web-extension.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import BasicAdapter from './basic';
import { typeOf } from '../utils/type-check';

const Ember = window.Ember;
const { run, typeOf } = Ember;
const { run } = Ember;
const { isArray } = Array;
const { keys } = Object;

Expand Down
4 changes: 3 additions & 1 deletion ember_debug/libs/glimmer-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@
*
* @class GlimmerTree
*/

const Ember = window.Ember;
import { typeOf } from '../utils/type-check';
import {
modelName as getModelName,
shortModelName as getShortModelName,
shortControllerName as getShortControllerName,
shortViewName as getShortViewName
} from 'ember-debug/utils/name-functions';

const { Object: EmberObject, typeOf, isNone, Controller, ViewUtils, get, A } = Ember;
const { Object: EmberObject, isNone, Controller, ViewUtils, get, A } = Ember;
const { getRootViews, getChildViews, getViewBoundingClientRect } = ViewUtils;

export default class {
Expand Down
4 changes: 3 additions & 1 deletion ember_debug/models/promise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { typeOf } from '../utils/type-check';

const Ember = window.Ember;
const { typeOf, Object: EmberObject, computed, A } = Ember;
const { Object: EmberObject, computed, A } = Ember;

const dateComputed = function() {
return computed({
Expand Down
17 changes: 3 additions & 14 deletions ember_debug/object-inspector.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import PortMixin from 'ember-debug/mixins/port-mixin';
import { compareVersion } from 'ember-debug/utils/version';
import { isComputed, isDescriptor, getDescriptorFor } from 'ember-debug/utils/type-check';
import { typeOf } from './utils/type-check';

const Ember = window.Ember;
const {
Object: EmberObject, inspect: emberInspect, meta: emberMeta, typeOf: emberTypeOf,
Object: EmberObject, inspect: emberInspect, meta: emberMeta,
computed, get, set, guidFor, isNone,
cacheFor, VERSION
} = Ember;
Expand All @@ -29,18 +30,6 @@ try {

const keys = Object.keys || Ember.keys;

/**
* workaround to support detection of `[object AsyncFunction]` as a function
* @param value
* @returns {string}
*/
function typeOf(value) {
if (typeof value === 'function') {
return 'function';
}
return emberTypeOf(value);
}

/**
* Determine the type and get the value of the passed property
* @param {*} object The parent object we will look for `key` on
Expand Down Expand Up @@ -111,7 +100,7 @@ function inspect(value) {
if (v === 'toString') {
continue;
} // ignore useless items
if (typeOf(v) === 'function') {
if (typeOf(v).includes('function')) {
v = 'function() { ... }';
}
if (typeOf(v) === 'array') {
Expand Down
5 changes: 5 additions & 0 deletions ember_debug/utils/type-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ export function getDescriptorFor(object, key) {

return object[key];
}


export function typeOf(obj) {
return Object.prototype.toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase();
}
2 changes: 1 addition & 1 deletion ember_debug/view-debug.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint no-cond-assign:0 */
import PortMixin from 'ember-debug/mixins/port-mixin';
import GlimmerTree from 'ember-debug/libs/glimmer-tree';
import { typeOf } from './utils/type-check';

const Ember = window.Ember;

Expand All @@ -9,7 +10,6 @@ const {
computed,
run,
Object: EmberObject,
typeOf,
Component,
String
} = Ember;
Expand Down

0 comments on commit 8d05d55

Please sign in to comment.