-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d183bc6
commit 6b14ff1
Showing
5 changed files
with
53 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 24 additions & 19 deletions
43
projects/$2sxc/src/sxc-instance/sxc-instance-with-internals.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters