Skip to content

Commit

Permalink
remove obsolete .data feature
Browse files Browse the repository at this point in the history
  • Loading branch information
iJungleboy committed Dec 3, 2021
1 parent d183bc6 commit 6b14ff1
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 27 deletions.
23 changes: 23 additions & 0 deletions projects/$2sxc/src/sxc-instance/data/sxc-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { SxcInstance } from "..";
import { SxcWebApi } from "../web-api/sxc-web-api";

export class SxcData {
private readonly webApi: SxcWebApi;

constructor(
private readonly sxc: SxcInstance,
readonly contentType: string
) {
this.webApi = sxc.webApi;

if (contentType == null) throw "contentType is empty";
if (contentType.indexOf("/") != -1 || contentType.indexOf("\\") != -1)
throw "contentType has slashes - not allowed";
}

get<T = any>(ids?: string | number, params?: string | Record<string, any>): Promise<T> {
let path = "app/auto/content/" + this.contentType;
if (ids && (typeof ids === 'string' || typeof ids === 'number')) path += "/" + ids;
return this.webApi.fetchJson(this.webApi.url(path, params));
}
}
2 changes: 0 additions & 2 deletions projects/$2sxc/src/sxc-instance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ export * from './sxc-instance-with-internals';
export * from './web-api/sxc-web-api';
export * from './web-api/ajax-promise';
export * from './web-api/ajax-settings';

export * from './deprecated/sxc-instance-data';
43 changes: 24 additions & 19 deletions projects/$2sxc/src/sxc-instance/sxc-instance-with-internals.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
import { SxcRootInternals } from '../sxc-root/sxc-root-internals';
import { SxcRoot } from '../sxc-root/sxc-root';
import { SxcInstance, SxcInstanceDataDeprecated } from '.';
import { SxcInstance } from '.';
import { ContextIdentifier } from '../sxc-root/context-identifier';

export class SxcInstanceWithInternals extends SxcInstance {
data: SxcInstanceDataDeprecated;
source: any = null;
isLoaded = false;
lastRefresh: Date = null;

constructor(
public id: number,
public cbid: number,
public cacheKey: string,
protected $2sxc: SxcRoot & SxcRootInternals,
ctx?: ContextIdentifier
source: any = null;
isLoaded = false;
lastRefresh: Date = null;

constructor(
public id: number,
public cbid: number,
public cacheKey: string,
protected $2sxc: SxcRoot & SxcRootInternals,
ctx?: ContextIdentifier
) {
super(id, cbid, $2sxc, ctx);
this.data = new SxcInstanceDataDeprecated(this);
}
super(id, cbid, $2sxc, ctx);

// Help cach error on call of old code
(this.data as any).on = () => {
throw 'Warning Obsolete Feature on 2sxc JS: the .data has been obsolete for a long time and is repurposed. \n'
+ 'If you are calling .data.on(...) you are running very old code. \n'
+ 'Guidance to fix this: https://r.2sxc.org/brc-13-id.'
};
}

recreate(resetCache: boolean): SxcInstanceWithInternals {
if (resetCache) delete this.$2sxc._controllers[this.cacheKey]; // clear cache
return this.$2sxc(this.id, this.cbid) as any as SxcInstanceWithInternals; // generate new
}
recreate(resetCache: boolean): SxcInstanceWithInternals {
if (resetCache) delete this.$2sxc._controllers[this.cacheKey]; // clear cache
return this.$2sxc(this.id, this.cbid) as any as SxcInstanceWithInternals; // generate new
}
}
5 changes: 5 additions & 0 deletions projects/$2sxc/src/sxc-instance/sxc-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SxcRoot } from '../sxc-root/sxc-root';
import { HasLog } from '..';
import { SxcRootInternals } from '../sxc-root/sxc-root-internals';
import { SxcInstanceManage } from './sxc-instance-manage';
import { SxcData } from './data/sxc-data';

// const serviceScopes = ['app', 'app-sys', 'app-api', 'app-query', 'app-content', 'eav', 'view', 'dnn'];

Expand Down Expand Up @@ -59,6 +60,10 @@ export class SxcInstance extends HasLog implements Public.SxcInstance {

}

data(contentType: string) {
return new SxcData(this, contentType);
}

/**
* converts a short api-call path like "/app/Blog/query/xyz" to the DNN full path
* which varies from installation to installation like "/desktopmodules/api/2sxc/app/..."
Expand Down
7 changes: 1 addition & 6 deletions projects/$2sxc/src/sxc-instance/web-api/sxc-web-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ import { NoJQ } from '../..';
*/
export class SxcWebApi implements Public.SxcWebApi {
public readonly env: Environment;
constructor(
private readonly sxc: SxcInstance,
// private readonly id: number,
// private readonly cbid: number,
// public readonly env: Environment
) {
constructor(private readonly sxc: SxcInstance) {
this.env = sxc.root.env;
}
/**
Expand Down

0 comments on commit 6b14ff1

Please sign in to comment.