Skip to content

Commit 350891f

Browse files
committed
- remove resolving Data Classes from the global scope
1 parent 0a19ed4 commit 350891f

File tree

5 files changed

+1
-95
lines changed

5 files changed

+1
-95
lines changed

backendless.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ declare module Backendless {
66
type JSONValue = string | number | boolean | { [x: string]: JSONValue } | Array<JSONValue>
77

88
let debugMode: boolean;
9-
let useTableClassesFromGlobalScope: boolean;
109
let serverURL: string;
1110
let appId: string;
1211
let apiKey: string;
@@ -39,7 +38,6 @@ declare module Backendless {
3938
domain?: string;
4039
debugMode?: boolean;
4140
XMLHttpRequest?: XMLHttpRequest;
42-
useTableClassesFromGlobalScope?: boolean;
4341
}
4442

4543
/**

src/data/store.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -449,19 +449,7 @@ const convertToClientRecords = (() => {
449449
delete source[prop].__subID
450450

451451
} else {
452-
let Model = context.classToTableMap[source[prop].___class]
453-
454-
if (!Model && context.app.useTableClassesFromGlobalScope && Utils.globalScope[source[prop].___class]) {
455-
// eslint-disable-next-line no-console
456-
console.warn(
457-
'Resolving DataTable classes from the global scope is deprecated ' +
458-
'and it won\'t be supported in the nearest future. ' +
459-
'Instead, you should register your DataTable classes ' +
460-
'using the following method Backendless.Data.mapTableToClass'
461-
)
462-
463-
Model = Utils.globalScope[source[prop].___class]
464-
}
452+
const Model = context.classToTableMap[source[prop].___class]
465453

466454
target[prop] = Model ? new Model() : {}
467455

src/index.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ const DEFAULT_PROPS = {
1515
XMLHttpRequest: typeof XMLHttpRequest !== 'undefined'
1616
? XMLHttpRequest
1717
: undefined,
18-
19-
//TODO: this is a temporary to disable getting DataTable classes from the global scope
20-
//TODO: it will be removed in the nearest future
21-
useTableClassesFromGlobalScope: true,
2218
}
2319

2420
const STATELESS_PROPS = ['appId', 'apiKey', 'domain']
@@ -260,15 +256,6 @@ class Backendless {
260256
)
261257
}
262258

263-
///--------useTableClassesFromGlobalScope-------///
264-
get useTableClassesFromGlobalScope() {
265-
return this.__useTableClassesFromGlobalScope
266-
}
267-
268-
set useTableClassesFromGlobalScope(useTableClassesFromGlobalScope) {
269-
this.__useTableClassesFromGlobalScope = !!useTableClassesFromGlobalScope
270-
}
271-
272259
///--------debugMode-------///
273260
get debugMode() {
274261
return this.__debugMode

test/tsd.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ function testMain() {
2424
apiKey: 'JS_SECRET_KEY',
2525
standalone: true,
2626
debugMode: true,
27-
useTableClassesFromGlobalScope: false,
2827
serverURL: 'serverURL'
2928
});
3029

test/unit/specs/data/parser.js

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2794,79 +2794,13 @@ describe('<Data> Parser', function() {
27942794
expect(result2[1]).to.be.instanceof(FooClass)
27952795
})
27962796

2797-
it('uses classes from global by default for data store object with inner instances', async () => {
2798-
// eslint-disable-next-line no-console
2799-
const _nativeConsoleWarn = console.warn
2800-
2801-
// eslint-disable-next-line no-console
2802-
const spyConsoleWarn = console.warn = chai.spy()
2803-
2804-
global.FooClass = class FooClass {
2805-
}
2806-
2807-
global.BarFun = function BarFun() {
2808-
}
2809-
2810-
dataStore = Backendless.Data.of(tableName)
2811-
2812-
const result1 = dataStore.parseResponse({
2813-
foo: { ___class: 'FooClass', value: 1, },
2814-
bar: { ___class: 'BarFun', value: 2, }
2815-
})
2816-
2817-
const result2 = dataStore.parseResponse([
2818-
{ foo: { ___class: 'FooClass', value: 3, }, bar: { ___class: 'BarFun', value: 5, } },
2819-
{ foo: { ___class: 'FooClass', value: 4, }, bar: { ___class: 'BarFun', value: 6, } }
2820-
])
2821-
2822-
expect(result1).to.be.eql({
2823-
foo: { ___class: 'FooClass', value: 1, },
2824-
bar: { ___class: 'BarFun', value: 2, }
2825-
})
2826-
2827-
expect(result1.foo).to.be.instanceof(FooClass)
2828-
expect(result1.bar).to.be.instanceof(BarFun)
2829-
2830-
expect(result2).to.be.eql([
2831-
{ foo: { ___class: 'FooClass', value: 3, }, bar: { ___class: 'BarFun', value: 5, } },
2832-
{ foo: { ___class: 'FooClass', value: 4, }, bar: { ___class: 'BarFun', value: 6, } }
2833-
])
2834-
2835-
expect(result2[0].foo).to.be.instanceof(FooClass)
2836-
expect(result2[0].bar).to.be.instanceof(BarFun)
2837-
2838-
expect(result2[1].foo).to.be.instanceof(FooClass)
2839-
expect(result2[1].bar).to.be.instanceof(BarFun)
2840-
2841-
expect(spyConsoleWarn).to.have.been.called.exactly(6)
2842-
2843-
const warningMsg = (
2844-
'Resolving DataTable classes from the global scope is deprecated ' +
2845-
'and it won\'t be supported in the nearest future. ' +
2846-
'Instead, you should register your DataTable classes ' +
2847-
'using the following method Backendless.Data.mapTableToClass'
2848-
)
2849-
2850-
expect(spyConsoleWarn).on.nth(1).be.called.with(warningMsg)
2851-
expect(spyConsoleWarn).on.nth(2).be.called.with(warningMsg)
2852-
expect(spyConsoleWarn).on.nth(3).be.called.with(warningMsg)
2853-
expect(spyConsoleWarn).on.nth(4).be.called.with(warningMsg)
2854-
expect(spyConsoleWarn).on.nth(5).be.called.with(warningMsg)
2855-
expect(spyConsoleWarn).on.nth(6).be.called.with(warningMsg)
2856-
2857-
// eslint-disable-next-line no-console
2858-
console.warn = _nativeConsoleWarn
2859-
})
2860-
28612797
it('does not use classes from global for data store object with inner instances', async () => {
28622798
// eslint-disable-next-line no-console
28632799
const _nativeConsoleWarn = console.warn
28642800

28652801
// eslint-disable-next-line no-console
28662802
const spyConsoleWarn = console.warn = chai.spy()
28672803

2868-
Backendless.useTableClassesFromGlobalScope = false
2869-
28702804
global.FooClass = class FooClass {
28712805
}
28722806

0 commit comments

Comments
 (0)