Skip to content

Commit d1a6894

Browse files
committed
feat(dts-generator): refactor TypedContext -> TypedJSONContext
1 parent 5387700 commit d1a6894

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

test-packages/typed-json-model/webapp/controller/App.controller.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Controller from "sap/ui/core/mvc/Controller";
2-
import { TypedContext, TypedJSONModel } from "../model/model";
2+
import { TypedJSONContext, TypedJSONModel } from "../model/model";
33
import { exampleBinding } from "./Example";
44
import { List$ItemClickEvent } from "sap/ui/webc/main/List";
55
import MessageBox from "sap/m/MessageBox";
@@ -55,7 +55,10 @@ export default class App extends Controller {
5555
* Example on how to how to use the typed context
5656
*/
5757
onPressItem(event: List$ItemClickEvent): void {
58-
const context = event.getSource().getBindingContext() as TypedContext<{ order: PurchaseOrder }, `/order/items/${bigint}`>;
58+
const context = event.getSource().getBindingContext() as TypedJSONContext<
59+
{ order: PurchaseOrder },
60+
`/order/items/${number}`
61+
>;
5962

6063
const price = context.getProperty("price"); // should automatically be typed as number!
6164
const description = this.model.getProperty("description", context); // should automatically be typed as string!

test-packages/typed-json-model/webapp/controller/Example.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TypedContext, TypedJSONModel } from "../model/model";
1+
import { TypedJSONContext, TypedJSONModel } from "../model/model";
22

33
interface Order {
44
order_id: string;
@@ -45,7 +45,7 @@ const data: { order: PurchaseOrder } = {
4545
*/
4646
export function exampleBinding() {
4747
const model = new TypedJSONModel(data);
48-
const typedContext = new TypedContext(model, "/order");
48+
const typedContext = new TypedJSONContext(model, "/order");
4949

5050
console.assert(typedContext.getProperty("approved") == true);
5151
console.assert(typedContext.getProperty("items/0/description") == "Notebook");

test-packages/typed-json-model/webapp/model/model.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
RelativeBindingPath,
88
} from "./typing";
99

10-
export class TypedContext<Data extends object, Root extends AbsoluteBindingPath<Data>> extends Context {
10+
export class TypedJSONContext<Data extends object, Root extends AbsoluteBindingPath<Data>> extends Context {
1111
constructor(oModel: TypedJSONModel<Data>, sPath: Root) {
1212
super(oModel, sPath);
1313
}
@@ -35,8 +35,8 @@ export class TypedJSONModel<Data extends object> extends JSONModel {
3535
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
3636
fnCallBack?: Function,
3737
bReload?: boolean,
38-
): TypedContext<Data, Path> {
39-
return super.createBindingContext(sPath, oContext, mParameters, fnCallBack, bReload) as TypedContext<Data, Path>;
38+
): TypedJSONContext<Data, Path> {
39+
return super.createBindingContext(sPath, oContext, mParameters, fnCallBack, bReload) as TypedJSONContext<Data, Path>;
4040
}
4141

4242
getData(): Data {
@@ -46,11 +46,11 @@ export class TypedJSONModel<Data extends object> extends JSONModel {
4646
getProperty<Path extends AbsoluteBindingPath<Data>>(sPath: Path): PropertyByAbsoluteBindingPath<Data, Path>;
4747
getProperty<Path extends RelativeBindingPath<Data, Root>, Root extends AbsoluteBindingPath<Data>>(
4848
sPath: Path,
49-
oContext: TypedContext<Data, Root>,
49+
oContext: TypedJSONContext<Data, Root>,
5050
): PropertyByRelativeBindingPath<Data, Root, Path>;
5151
getProperty<Path extends AbsoluteBindingPath<Data> | RelativeBindingPath<Data, Root>, Root extends AbsoluteBindingPath<Data>>(
5252
sPath: Path,
53-
oContext?: TypedContext<Data, Root>,
53+
oContext?: TypedJSONContext<Data, Root>,
5454
): PropertyByAbsoluteBindingPath<Data, Path> | PropertyByRelativeBindingPath<Data, Root, Path> {
5555
return super.getProperty(sPath, oContext) as
5656
| PropertyByAbsoluteBindingPath<Data, Path>
@@ -73,15 +73,15 @@ export class TypedJSONModel<Data extends object> extends JSONModel {
7373
setProperty<Path extends RelativeBindingPath<Data, Root>, Root extends AbsoluteBindingPath<Data>>(
7474
sPath: Path,
7575
oValue: PropertyByRelativeBindingPath<Data, Root, Path>,
76-
oContext: TypedContext<Data, Root>,
76+
oContext: TypedJSONContext<Data, Root>,
7777
bAsyncUpdate?: boolean,
7878
): boolean;
7979
setProperty<Path extends AbsoluteBindingPath<Data> | RelativeBindingPath<Data, Root>, Root extends AbsoluteBindingPath<Data>>(
8080
sPath: Path,
8181
oValue: Path extends AbsoluteBindingPath<Data>
8282
? PropertyByAbsoluteBindingPath<Data, Path>
8383
: PropertyByRelativeBindingPath<Data, Root, Path>,
84-
oContext?: TypedContext<Data, Root>,
84+
oContext?: TypedJSONContext<Data, Root>,
8585
bAsyncUpdate?: boolean,
8686
): boolean {
8787
return super.setProperty(sPath, oValue, oContext, bAsyncUpdate);

0 commit comments

Comments
 (0)