added typescript

This commit is contained in:
hariroshan 2023-01-05 13:34:51 +05:30
parent f625530474
commit 51051f7961
11 changed files with 100 additions and 47 deletions

View File

@ -1,10 +1,10 @@
/*
In NativeScript, the app.js file is the entry point to your application.
In NativeScript, the app.ts file is the entry point to your application.
You can use this file to perform app-level initialization, but the primary
purpose of the file is to pass control to the apps first module.
*/
import { Application } from '@nativescript/core';
import { Application } from '@nativescript/core'
Application.run({ moduleName: 'app-root' })

View File

@ -1,6 +0,0 @@
import { createViewModel } from './main-view-model';
export function onNavigatingTo(args) {
const page = args.object
page.bindingContext = createViewModel()
}

7
app/main-page.ts Normal file
View File

@ -0,0 +1,7 @@
import { EventData, Page } from '@nativescript/core'
import { HelloWorldModel } from './main-view-model'
export function navigatingTo(args: EventData) {
const page = <Page>args.object
page.bindingContext = new HelloWorldModel()
}

View File

@ -1,4 +1,4 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="onNavigatingTo">
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo">
<ActionBar title="My App" icon="" />
<StackLayout class="p-20">

View File

@ -1,23 +0,0 @@
import { Observable } from '@nativescript/core'
function getMessage(counter) {
if (counter <= 0) {
return 'Hoorraaay! You unlocked the NativeScript clicker achievement!'
} else {
return `${counter} taps left`
}
}
export function createViewModel() {
const viewModel = new Observable()
viewModel.counter = 42
viewModel.message = getMessage(viewModel.counter)
viewModel.onTap = () => {
viewModel.counter--
viewModel.set('message', getMessage(viewModel.counter))
}
return viewModel
}

38
app/main-view-model.ts Normal file
View File

@ -0,0 +1,38 @@
import { Observable } from '@nativescript/core'
export class HelloWorldModel extends Observable {
private _counter: number
private _message: string
constructor() {
super()
// Initialize default values.
this._counter = 42
this.updateMessage()
}
get message(): string {
return this._message
}
set message(value: string) {
if (this._message !== value) {
this._message = value
this.notifyPropertyChange('message', value)
}
}
onTap() {
this._counter--
this.updateMessage()
}
private updateMessage() {
if (this._counter <= 0) {
this.message = 'Hoorraaay! You unlocked the NativeScript clicker achievement!'
} else {
this.message = `${this._counter} taps left`
}
}
}

View File

@ -1,10 +0,0 @@
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"~/*": ["app/*"],
"@/*": ["app/*"]
}
},
"include": ["app/**/*"]
}

View File

@ -1,18 +1,20 @@
{
"name": "elm-native",
"main": "app/app.js",
"main": "app/app.ts",
"version": "1.0.0",
"private": true,
"dependencies": {
"@nativescript/core": "~8.4.0",
"@nativescript/theme": "~3.0.2"
},
"scripts": {
"res:build": "rescript",
"res:dev": "rescript build -w"
},
"dependencies": {
"@nativescript/core": "~8.4.0",
"@nativescript/theme": "~3.0.2"
},
"devDependencies": {
"@nativescript/types": "~8.4.0",
"@nativescript/webpack": "~5.0.12",
"typescript": "~4.8.4",
"rescript": "^10.0.1"
}
}

1
references.d.ts vendored Normal file
View File

@ -0,0 +1 @@
/// <reference path="./node_modules/@nativescript/types/index.d.ts" />

21
tsconfig.json Normal file
View File

@ -0,0 +1,21 @@
{
"compilerOptions": {
"module": "esnext",
"target": "es2017",
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"noEmitHelpers": true,
"noEmitOnError": true,
"skipLibCheck": true,
"lib": ["es2017", "dom"],
"baseUrl": ".",
"paths": {
"~/*": ["app/*"],
"@/*": ["app/*"]
}
},
"include": ["app/**/*"],
"files": ["./references.d.ts"],
"exclude": ["node_modules", "platforms"]
}

View File

@ -268,6 +268,24 @@
resolved "https://registry.yarnpkg.com/@nativescript/theme/-/theme-3.0.2.tgz#9584ad8988dea937f0f32629b80954de886c6c20"
integrity sha512-ypwYyasTFRWbaxNwdqXgql9MUZsq82Stgd+zj4LEjp5cBQPPIWFeJ8uxWdtbpjHjjuTWYW/FCMmnuayOF7uK/g==
"@nativescript/types-android@~8.4.0":
version "8.4.0"
resolved "https://registry.yarnpkg.com/@nativescript/types-android/-/types-android-8.4.0.tgz#2fa1325f43cd1343e53ddc51ef0ad1b42297c433"
integrity sha512-WmDVH72ZeBlxy7k5OAJFk7wPSW9K2xjRzFwHAkQ1mjKr7k+UcFzGkpbAXjtgQZ5SybBPCzYGLGcvv7kJDNJ/mQ==
"@nativescript/types-ios@~8.4.0":
version "8.4.0"
resolved "https://registry.yarnpkg.com/@nativescript/types-ios/-/types-ios-8.4.0.tgz#4c0a0ee1d4f5e9ce237a768a6f8797a24723b13f"
integrity sha512-6Sx4yuSar2qk4UpYtZCs9B53Jv0wLRGvrg6Vsg5tC8mdYeQOKsizNxPa625pHbFrNjTF8NkdoGOGZiFM/XkiOQ==
"@nativescript/types@~8.4.0":
version "8.4.0"
resolved "https://registry.yarnpkg.com/@nativescript/types/-/types-8.4.0.tgz#7b68c25ce1971b5ad37004c250d648bf9ef4a764"
integrity sha512-AsHLbzYi/3rNAQYxG5etVlTiq96KG+RHJ+UgZ3zynER4vw+mLN6TkVJ9hR6ciKMfFhQBM0JZvxBuHqm3xmlRzw==
dependencies:
"@nativescript/types-android" "~8.4.0"
"@nativescript/types-ios" "~8.4.0"
"@nativescript/webpack@~5.0.12":
version "5.0.12"
resolved "https://registry.yarnpkg.com/@nativescript/webpack/-/webpack-5.0.12.tgz#7fb73f6cc2bd622ef1df39374590d46d1831aca3"
@ -2271,6 +2289,11 @@ tslib@^2.0.0:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.1.tgz#0d0bfbaac2880b91e22df0768e55be9753a5b17e"
integrity sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==
typescript@~4.8.4:
version "4.8.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.8.4.tgz#c464abca159669597be5f96b8943500b238e60e6"
integrity sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==
universalify@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"