├── .gitignore
├── LICENSE
├── README.md
├── demo
├── app
│ ├── App_Resources
│ │ ├── Android
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── app.gradle
│ │ │ ├── drawable-hdpi
│ │ │ │ ├── background.png
│ │ │ │ ├── icon.png
│ │ │ │ └── logo.png
│ │ │ ├── drawable-ldpi
│ │ │ │ ├── background.png
│ │ │ │ ├── icon.png
│ │ │ │ └── logo.png
│ │ │ ├── drawable-mdpi
│ │ │ │ ├── background.png
│ │ │ │ ├── icon.png
│ │ │ │ └── logo.png
│ │ │ ├── drawable-nodpi
│ │ │ │ └── splash_screen.xml
│ │ │ ├── drawable-xhdpi
│ │ │ │ ├── background.png
│ │ │ │ ├── icon.png
│ │ │ │ └── logo.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ ├── background.png
│ │ │ │ ├── icon.png
│ │ │ │ └── logo.png
│ │ │ ├── drawable-xxxhdpi
│ │ │ │ ├── background.png
│ │ │ │ ├── icon.png
│ │ │ │ └── logo.png
│ │ │ ├── values-v21
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ └── values
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ └── iOS
│ │ │ ├── Assets.xcassets
│ │ │ ├── AppIcon.appiconset
│ │ │ │ ├── Contents.json
│ │ │ │ ├── icon-29.png
│ │ │ │ ├── icon-29@2x.png
│ │ │ │ ├── icon-29@3x.png
│ │ │ │ ├── icon-40.png
│ │ │ │ ├── icon-40@2x.png
│ │ │ │ ├── icon-40@3x.png
│ │ │ │ ├── icon-50.png
│ │ │ │ ├── icon-50@2x.png
│ │ │ │ ├── icon-57.png
│ │ │ │ ├── icon-57@2x.png
│ │ │ │ ├── icon-60@2x.png
│ │ │ │ ├── icon-60@3x.png
│ │ │ │ ├── icon-72.png
│ │ │ │ ├── icon-72@2x.png
│ │ │ │ ├── icon-76.png
│ │ │ │ ├── icon-76@2x.png
│ │ │ │ └── icon-83.5@2x.png
│ │ │ ├── Contents.json
│ │ │ ├── LaunchImage.launchimage
│ │ │ │ ├── Contents.json
│ │ │ │ ├── Default-568h@2x.png
│ │ │ │ ├── Default-667h@2x.png
│ │ │ │ ├── Default-736h@3x.png
│ │ │ │ ├── Default-Landscape.png
│ │ │ │ ├── Default-Landscape@2x.png
│ │ │ │ ├── Default-Landscape@3x.png
│ │ │ │ ├── Default-Portrait.png
│ │ │ │ ├── Default-Portrait@2x.png
│ │ │ │ ├── Default.png
│ │ │ │ └── Default@2x.png
│ │ │ ├── LaunchScreen.AspectFill.imageset
│ │ │ │ ├── Contents.json
│ │ │ │ ├── LaunchScreen-AspectFill.png
│ │ │ │ └── LaunchScreen-AspectFill@2x.png
│ │ │ └── LaunchScreen.Center.imageset
│ │ │ │ ├── Contents.json
│ │ │ │ ├── LaunchScreen-Center.png
│ │ │ │ └── LaunchScreen-Center@2x.png
│ │ │ ├── Info.plist
│ │ │ ├── LaunchScreen.storyboard
│ │ │ └── build.xcconfig
│ ├── app.css
│ ├── app.js
│ ├── app.ts
│ ├── bundle-config.js
│ ├── main-page.js
│ ├── main-page.xml
│ ├── main-view-model.js
│ ├── package.json
│ └── references.d.ts
├── hooks
│ ├── after-prepare
│ │ └── nativescript-dev-android-snapshot.js
│ ├── before-prepare
│ │ ├── nativescript-dev-android-snapshot.js
│ │ └── nativescript-dev-typescript.js
│ └── before-watch
│ │ └── nativescript-dev-typescript.js
├── livesync.cmd
├── package.json
├── references.d.ts
└── tsconfig.json
└── plugin
├── .npmignore
├── README.md
├── index.d.ts
├── index.js
├── index.ts
├── package.json
├── references.d.ts
├── tsconfig.json
└── worker.js
/.gitignore:
--------------------------------------------------------------------------------
1 | /pushall.sh
2 | /demo/platforms
3 | /demo/node_modules
4 | /plugin/*.map
5 | /demo/app/*.map
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Marcel Kloubert
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://www.npmjs.com/package/nativescript-tasks)
2 | [](https://www.npmjs.com/package/nativescript-tasks)
3 |
4 | # NativeScript Tasks
5 |
6 | A [NativeScript](https://nativescript.org/) module for simply handling background tasks via web workers.
7 |
8 | [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DE5KRMBB3N2U8)
9 |
10 | ## License
11 |
12 | [MIT license](https://raw.githubusercontent.com/mkloubert/nativescript-tasks/master/LICENSE)
13 |
14 | ## Platforms
15 |
16 | * Android
17 | * iOS
18 |
19 | ## Requirements
20 |
21 | * NativeScript 2.4+ (s. [Multithreading Model](https://docs.nativescript.org/core-concepts/multithreading-model))
22 |
23 | ## Installation
24 |
25 | Run
26 |
27 | ```bash
28 | tns plugin add nativescript-tasks
29 | ```
30 |
31 | inside your app project to install the module.
32 |
33 | ## Example
34 |
35 | ```typescript
36 | import Tasks = require("nativescript-tasks");
37 |
38 | Tasks.startNew((ctx) => {
39 | return 23979 + ctx.state;
40 | },
41 | 5979) // 5979 will be stored in 'state'
42 | // property of 'ctx'
43 | .then((result) => {
44 | console.log('Result: ' + result.data); // 29958
45 | // result.state = 5979
46 | })
47 | .catch((result) => {
48 | console.log('ERROR: ' + result.error);
49 | // result.state = 5979
50 | });
51 | ```
52 |
53 | ## Limitations
54 |
55 | * You can only submit and return serializable objects and values!
56 | * All task functions are 'closures', what means that you CANNOT access variables or modules outside such functions. All functions are serialized as strings and submitted to the [worker script](https://github.com/mkloubert/nativescript-tasks/blob/master/plugin/worker.js) where "external stuff" is NOT available! The only way to share data with the functions is to submit an optional and serializable "state value".
57 |
58 | Read the [official documentation](https://docs.nativescript.org/core-concepts/multithreading-model#limitations) to get more information.
59 |
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
16 |
17 |
18 |
19 |
20 |
21 |
27 |
28 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/app.gradle:
--------------------------------------------------------------------------------
1 | // Add your native dependencies here:
2 |
3 | // Uncomment to add recyclerview-v7 dependency
4 | //dependencies {
5 | // compile 'com.android.support:recyclerview-v7:+'
6 | //}
7 |
8 | android {
9 | defaultConfig {
10 | generatedDensities = []
11 | applicationId = "org.nativescript.NativeScriptTasksDemo"
12 |
13 | //override supported platforms
14 | // ndk {
15 | // abiFilters.clear()
16 | // abiFilters "armeabi-v7a"
17 | // }
18 |
19 | }
20 | aaptOptions {
21 | additionalParameters "--no-version-vectors"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/drawable-hdpi/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/Android/drawable-hdpi/background.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/drawable-hdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/Android/drawable-hdpi/icon.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/drawable-hdpi/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/Android/drawable-hdpi/logo.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/drawable-ldpi/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/Android/drawable-ldpi/background.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/drawable-ldpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/Android/drawable-ldpi/icon.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/drawable-ldpi/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/Android/drawable-ldpi/logo.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/drawable-mdpi/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/Android/drawable-mdpi/background.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/drawable-mdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/Android/drawable-mdpi/icon.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/drawable-mdpi/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/Android/drawable-mdpi/logo.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/drawable-nodpi/splash_screen.xml:
--------------------------------------------------------------------------------
1 |
2 | -
3 |
4 |
5 | -
6 |
7 |
8 |
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/drawable-xhdpi/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/Android/drawable-xhdpi/background.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/drawable-xhdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/Android/drawable-xhdpi/icon.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/drawable-xhdpi/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/Android/drawable-xhdpi/logo.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/drawable-xxhdpi/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/Android/drawable-xxhdpi/background.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/drawable-xxhdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/Android/drawable-xxhdpi/icon.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/drawable-xxhdpi/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/Android/drawable-xxhdpi/logo.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/drawable-xxxhdpi/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/Android/drawable-xxxhdpi/background.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/drawable-xxxhdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/Android/drawable-xxxhdpi/icon.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/drawable-xxxhdpi/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/Android/drawable-xxxhdpi/logo.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/values-v21/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3d5afe
4 |
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
9 |
10 |
11 |
14 |
15 |
16 |
19 |
20 |
23 |
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #F5F5F5
4 | #757575
5 | #33B5E5
6 | #272734
7 |
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
18 |
19 |
21 |
22 |
23 |
31 |
32 |
34 |
35 |
36 |
42 |
43 |
45 |
46 |
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "size" : "29x29",
5 | "idiom" : "iphone",
6 | "filename" : "icon-29.png",
7 | "scale" : "1x"
8 | },
9 | {
10 | "size" : "29x29",
11 | "idiom" : "iphone",
12 | "filename" : "icon-29@2x.png",
13 | "scale" : "2x"
14 | },
15 | {
16 | "size" : "29x29",
17 | "idiom" : "iphone",
18 | "filename" : "icon-29@3x.png",
19 | "scale" : "3x"
20 | },
21 | {
22 | "size" : "40x40",
23 | "idiom" : "iphone",
24 | "filename" : "icon-40@2x.png",
25 | "scale" : "2x"
26 | },
27 | {
28 | "size" : "40x40",
29 | "idiom" : "iphone",
30 | "filename" : "icon-40@3x.png",
31 | "scale" : "3x"
32 | },
33 | {
34 | "size" : "57x57",
35 | "idiom" : "iphone",
36 | "filename" : "icon-57.png",
37 | "scale" : "1x"
38 | },
39 | {
40 | "size" : "57x57",
41 | "idiom" : "iphone",
42 | "filename" : "icon-57@2x.png",
43 | "scale" : "2x"
44 | },
45 | {
46 | "size" : "60x60",
47 | "idiom" : "iphone",
48 | "filename" : "icon-60@2x.png",
49 | "scale" : "2x"
50 | },
51 | {
52 | "size" : "60x60",
53 | "idiom" : "iphone",
54 | "filename" : "icon-60@3x.png",
55 | "scale" : "3x"
56 | },
57 | {
58 | "size" : "29x29",
59 | "idiom" : "ipad",
60 | "filename" : "icon-29.png",
61 | "scale" : "1x"
62 | },
63 | {
64 | "size" : "29x29",
65 | "idiom" : "ipad",
66 | "filename" : "icon-29@2x.png",
67 | "scale" : "2x"
68 | },
69 | {
70 | "size" : "40x40",
71 | "idiom" : "ipad",
72 | "filename" : "icon-40.png",
73 | "scale" : "1x"
74 | },
75 | {
76 | "size" : "40x40",
77 | "idiom" : "ipad",
78 | "filename" : "icon-40@2x.png",
79 | "scale" : "2x"
80 | },
81 | {
82 | "size" : "50x50",
83 | "idiom" : "ipad",
84 | "filename" : "icon-50.png",
85 | "scale" : "1x"
86 | },
87 | {
88 | "size" : "50x50",
89 | "idiom" : "ipad",
90 | "filename" : "icon-50@2x.png",
91 | "scale" : "2x"
92 | },
93 | {
94 | "size" : "72x72",
95 | "idiom" : "ipad",
96 | "filename" : "icon-72.png",
97 | "scale" : "1x"
98 | },
99 | {
100 | "size" : "72x72",
101 | "idiom" : "ipad",
102 | "filename" : "icon-72@2x.png",
103 | "scale" : "2x"
104 | },
105 | {
106 | "size" : "76x76",
107 | "idiom" : "ipad",
108 | "filename" : "icon-76.png",
109 | "scale" : "1x"
110 | },
111 | {
112 | "size" : "76x76",
113 | "idiom" : "ipad",
114 | "filename" : "icon-76@2x.png",
115 | "scale" : "2x"
116 | },
117 | {
118 | "size" : "83.5x83.5",
119 | "idiom" : "ipad",
120 | "filename" : "icon-83.5@2x.png",
121 | "scale" : "2x"
122 | }
123 | ],
124 | "info" : {
125 | "version" : 1,
126 | "author" : "xcode"
127 | }
128 | }
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-29.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-29.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-29@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-29@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-29@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-29@3x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-40.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-40.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-40@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-40@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-40@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-40@3x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-50.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-50.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-50@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-50@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-57.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-57.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-57@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-57@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-60@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-60@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-60@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-60@3x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-72.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-72.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-72@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-72@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-76.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-76.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-76@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-76@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-83.5@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-83.5@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "extent" : "full-screen",
5 | "idiom" : "iphone",
6 | "subtype" : "736h",
7 | "filename" : "Default-736h@3x.png",
8 | "minimum-system-version" : "8.0",
9 | "orientation" : "portrait",
10 | "scale" : "3x"
11 | },
12 | {
13 | "extent" : "full-screen",
14 | "idiom" : "iphone",
15 | "subtype" : "736h",
16 | "filename" : "Default-Landscape@3x.png",
17 | "minimum-system-version" : "8.0",
18 | "orientation" : "landscape",
19 | "scale" : "3x"
20 | },
21 | {
22 | "extent" : "full-screen",
23 | "idiom" : "iphone",
24 | "subtype" : "667h",
25 | "filename" : "Default-667h@2x.png",
26 | "minimum-system-version" : "8.0",
27 | "orientation" : "portrait",
28 | "scale" : "2x"
29 | },
30 | {
31 | "orientation" : "portrait",
32 | "idiom" : "iphone",
33 | "filename" : "Default@2x.png",
34 | "extent" : "full-screen",
35 | "minimum-system-version" : "7.0",
36 | "scale" : "2x"
37 | },
38 | {
39 | "extent" : "full-screen",
40 | "idiom" : "iphone",
41 | "subtype" : "retina4",
42 | "filename" : "Default-568h@2x.png",
43 | "minimum-system-version" : "7.0",
44 | "orientation" : "portrait",
45 | "scale" : "2x"
46 | },
47 | {
48 | "orientation" : "portrait",
49 | "idiom" : "ipad",
50 | "filename" : "Default-Portrait.png",
51 | "extent" : "full-screen",
52 | "minimum-system-version" : "7.0",
53 | "scale" : "1x"
54 | },
55 | {
56 | "orientation" : "landscape",
57 | "idiom" : "ipad",
58 | "filename" : "Default-Landscape.png",
59 | "extent" : "full-screen",
60 | "minimum-system-version" : "7.0",
61 | "scale" : "1x"
62 | },
63 | {
64 | "orientation" : "portrait",
65 | "idiom" : "ipad",
66 | "filename" : "Default-Portrait@2x.png",
67 | "extent" : "full-screen",
68 | "minimum-system-version" : "7.0",
69 | "scale" : "2x"
70 | },
71 | {
72 | "orientation" : "landscape",
73 | "idiom" : "ipad",
74 | "filename" : "Default-Landscape@2x.png",
75 | "extent" : "full-screen",
76 | "minimum-system-version" : "7.0",
77 | "scale" : "2x"
78 | },
79 | {
80 | "orientation" : "portrait",
81 | "idiom" : "iphone",
82 | "filename" : "Default.png",
83 | "extent" : "full-screen",
84 | "scale" : "1x"
85 | },
86 | {
87 | "orientation" : "portrait",
88 | "idiom" : "iphone",
89 | "filename" : "Default@2x.png",
90 | "extent" : "full-screen",
91 | "scale" : "2x"
92 | },
93 | {
94 | "orientation" : "portrait",
95 | "idiom" : "iphone",
96 | "filename" : "Default-568h@2x.png",
97 | "extent" : "full-screen",
98 | "subtype" : "retina4",
99 | "scale" : "2x"
100 | },
101 | {
102 | "orientation" : "portrait",
103 | "idiom" : "ipad",
104 | "extent" : "to-status-bar",
105 | "scale" : "1x"
106 | },
107 | {
108 | "orientation" : "portrait",
109 | "idiom" : "ipad",
110 | "filename" : "Default-Portrait.png",
111 | "extent" : "full-screen",
112 | "scale" : "1x"
113 | },
114 | {
115 | "orientation" : "landscape",
116 | "idiom" : "ipad",
117 | "extent" : "to-status-bar",
118 | "scale" : "1x"
119 | },
120 | {
121 | "orientation" : "landscape",
122 | "idiom" : "ipad",
123 | "filename" : "Default-Landscape.png",
124 | "extent" : "full-screen",
125 | "scale" : "1x"
126 | },
127 | {
128 | "orientation" : "portrait",
129 | "idiom" : "ipad",
130 | "extent" : "to-status-bar",
131 | "scale" : "2x"
132 | },
133 | {
134 | "orientation" : "portrait",
135 | "idiom" : "ipad",
136 | "filename" : "Default-Portrait@2x.png",
137 | "extent" : "full-screen",
138 | "scale" : "2x"
139 | },
140 | {
141 | "orientation" : "landscape",
142 | "idiom" : "ipad",
143 | "extent" : "to-status-bar",
144 | "scale" : "2x"
145 | },
146 | {
147 | "orientation" : "landscape",
148 | "idiom" : "ipad",
149 | "filename" : "Default-Landscape@2x.png",
150 | "extent" : "full-screen",
151 | "scale" : "2x"
152 | }
153 | ],
154 | "info" : {
155 | "version" : 1,
156 | "author" : "xcode"
157 | }
158 | }
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-568h@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-568h@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-667h@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-667h@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-736h@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-736h@3x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Landscape.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Landscape.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Landscape@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Landscape@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Landscape@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Landscape@3x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Portrait.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Portrait.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Portrait@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Portrait@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.AspectFill.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "LaunchScreen-AspectFill.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "LaunchScreen-AspectFill@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "scale" : "3x"
16 | }
17 | ],
18 | "info" : {
19 | "version" : 1,
20 | "author" : "xcode"
21 | }
22 | }
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.AspectFill.imageset/LaunchScreen-AspectFill.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.AspectFill.imageset/LaunchScreen-AspectFill.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.AspectFill.imageset/LaunchScreen-AspectFill@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.AspectFill.imageset/LaunchScreen-AspectFill@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.Center.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "LaunchScreen-Center.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "LaunchScreen-Center@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "scale" : "3x"
16 | }
17 | ],
18 | "info" : {
19 | "version" : 1,
20 | "author" : "xcode"
21 | }
22 | }
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.Center.imageset/LaunchScreen-Center.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.Center.imageset/LaunchScreen-Center.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.Center.imageset/LaunchScreen-Center@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkloubert/nativescript-tasks/c25b6a484d57081cd1da639677664ee5521d98c6/demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.Center.imageset/LaunchScreen-Center@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleDisplayName
8 | ${PRODUCT_NAME}
9 | CFBundleExecutable
10 | ${EXECUTABLE_NAME}
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | ${PRODUCT_NAME}
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1.0
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIRequiresFullScreen
28 |
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 | UISupportedInterfaceOrientations~ipad
40 |
41 | UIInterfaceOrientationPortrait
42 | UIInterfaceOrientationPortraitUpsideDown
43 | UIInterfaceOrientationLandscapeLeft
44 | UIInterfaceOrientationLandscapeRight
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/build.xcconfig:
--------------------------------------------------------------------------------
1 | // You can add custom settings here
2 | // for example you can uncomment the following line to force distribution code signing
3 | // CODE_SIGN_IDENTITY = iPhone Distribution
4 | // To build for device with Xcode 8 you need to specify your development team. More info: https://developer.apple.com/library/prerelease/content/releasenotes/DeveloperTools/RN-Xcode/Introduction.html
5 | // DEVELOPMENT_TEAM = YOUR_TEAM_ID;
6 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
7 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
8 |
--------------------------------------------------------------------------------
/demo/app/app.css:
--------------------------------------------------------------------------------
1 | /*
2 | In NativeScript, the app.css file is where you place CSS rules that
3 | you would like to apply to your entire application. Check out
4 | http://docs.nativescript.org/ui/styling for a full list of the CSS
5 | selectors and properties you can use to style UI components.
6 |
7 | /*
8 | For example, the following CSS rule changes the font size of all UI
9 | components that have the btn class name.
10 | */
11 | .btn {
12 | font-size: 18;
13 | }
14 |
15 | /*
16 | In many cases you may want to use the NativeScript core theme instead
17 | of writing your own CSS rules. For a full list of class names in the theme
18 | refer to http://docs.nativescript.org/ui/theme.
19 | */
20 | @import 'nativescript-theme-core/css/core.light.css';
21 |
--------------------------------------------------------------------------------
/demo/app/app.js:
--------------------------------------------------------------------------------
1 | /*
2 | In NativeScript, the app.js file is the entry point to your application.
3 | You can use this file to perform app-level initialization, but the primary
4 | purpose of the file is to pass control to the app’s first module.
5 | */
6 | "use strict";
7 | require("./bundle-config");
8 | var Application = require("application");
9 | var Tasks = require('nativescript-tasks');
10 | Application.start({ moduleName: "main-page" });
11 | var t = Tasks.newTask(function (ctx) {
12 | var a = 1000;
13 | var b = 200;
14 | var c = ctx.state;
15 | // return 0;
16 | return (a + b * c + 7);
17 | }).start(30).then(function (result) {
18 | console.log('result: ' + result.data);
19 | }).catch(function (result) {
20 | console.log('error: ' + result.error);
21 | });
22 | /*
23 | Do not place any code after the application has been started as it will not
24 | be executed on iOS.
25 | */
26 | //# sourceMappingURL=app.js.map
--------------------------------------------------------------------------------
/demo/app/app.ts:
--------------------------------------------------------------------------------
1 | /*
2 | In NativeScript, the app.js file is the entry point to your application.
3 | You can use this file to perform app-level initialization, but the primary
4 | purpose of the file is to pass control to the app’s first module.
5 | */
6 |
7 | require("./bundle-config");
8 |
9 | import Application = require("application");
10 | import Tasks = require('nativescript-tasks');
11 |
12 | Application.start({ moduleName: "main-page" });
13 |
14 | let t = Tasks.newTask(function(ctx) {
15 | var a = 1000;
16 | var b = 200;
17 | var c = ctx.state;
18 |
19 | // return 0;
20 |
21 | return (a + b * c + 7);
22 | }).start(30).then((result) => {
23 | console.log('result: ' + result.data);
24 | }).catch((result) => {
25 | console.log('error: ' + result.error);
26 | });
27 |
28 | /*
29 | Do not place any code after the application has been started as it will not
30 | be executed on iOS.
31 | */
32 |
--------------------------------------------------------------------------------
/demo/app/bundle-config.js:
--------------------------------------------------------------------------------
1 | if (global.TNS_WEBPACK) {
2 | //registers tns-core-modules UI framework modules
3 | require("bundle-entry-points");
4 |
5 | //register application modules
6 | global.registerModule("main-page", function () { return require("./main-page"); });
7 | }
8 |
--------------------------------------------------------------------------------
/demo/app/main-page.js:
--------------------------------------------------------------------------------
1 | /*
2 | In NativeScript, a file with the same name as an XML file is known as
3 | a code-behind file. The code-behind is a great place to place your view
4 | logic, and to set up your page’s data binding.
5 | */
6 |
7 | /*
8 | NativeScript adheres to the CommonJS specification for dealing with
9 | JavaScript modules. The CommonJS require() function is how you import
10 | JavaScript modules defined in other files.
11 | */
12 | var createViewModel = require("./main-view-model").createViewModel;
13 |
14 | function onNavigatingTo(args) {
15 | /*
16 | This gets a reference this page’s UI component. You can
17 | view the API reference of the Page to see what’s available at
18 | https://docs.nativescript.org/api-reference/classes/_ui_page_.page.html
19 | */
20 | var page = args.object;
21 |
22 | /*
23 | A page’s bindingContext is an object that should be used to perform
24 | data binding between XML markup and JavaScript code. Properties
25 | on the bindingContext can be accessed using the {{ }} syntax in XML.
26 | In this example, the {{ message }} and {{ onTap }} bindings are resolved
27 | against the object returned by createViewModel().
28 |
29 | You can learn more about data binding in NativeScript at
30 | https://docs.nativescript.org/core-concepts/data-binding.
31 | */
32 | page.bindingContext = createViewModel();
33 | }
34 |
35 | /*
36 | Exporting a function in a NativeScript code-behind file makes it accessible
37 | to the file’s corresponding XML file. In this case, exporting the onNavigatingTo
38 | function here makes the navigatingTo="onNavigatingTo" binding in this page’s XML
39 | file work.
40 | */
41 | exports.onNavigatingTo = onNavigatingTo;
--------------------------------------------------------------------------------
/demo/app/main-page.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/demo/app/main-view-model.js:
--------------------------------------------------------------------------------
1 | var Observable = require("data/observable").Observable;
2 |
3 | function getMessage(counter) {
4 | if (counter <= 0) {
5 | return "Hoorraaay! You unlocked the NativeScript clicker achievement!";
6 | } else {
7 | return counter + " taps left";
8 | }
9 | }
10 |
11 | function createViewModel() {
12 | var viewModel = new Observable();
13 | viewModel.counter = 42;
14 | viewModel.message = getMessage(viewModel.counter);
15 |
16 | viewModel.onTap = function() {
17 | this.counter--;
18 | this.set("message", getMessage(this.counter));
19 | }
20 |
21 | return viewModel;
22 | }
23 |
24 | exports.createViewModel = createViewModel;
--------------------------------------------------------------------------------
/demo/app/package.json:
--------------------------------------------------------------------------------
1 | {"name":"tns-template-hello-world","main":"app.js","version":"2.4.1","author":{"name":"Telerik","email":"support@telerik.com"},"description":"Nativescript hello-world project template","license":"Apache-2.0","keywords":["telerik","mobile","nativescript","{N}","tns","appbuilder","template"],"repository":{"type":"git","url":"git://github.com/NativeScript/template-hello-world.git"},"bugs":{"url":"https://github.com/NativeScript/template-hello-world/issues"},"homepage":"https://github.com/NativeScript/template-hello-world","android":{"v8Flags":"--expose_gc"},"dependencies":{"nativescript-theme-core":"^0.2.1"},"devDependencies":{"nativescript-dev-android-snapshot":"^0.*.*"},"readme":"ERROR: No README data found!","_id":"tns-template-hello-world@2.4.1","_from":"tns-template-hello-world@2.4.1"}
--------------------------------------------------------------------------------
/demo/app/references.d.ts:
--------------------------------------------------------------------------------
1 | /// Enable smart suggestions and completions in Visual Studio Code JavaScript projects.
2 |
--------------------------------------------------------------------------------
/demo/hooks/after-prepare/nativescript-dev-android-snapshot.js:
--------------------------------------------------------------------------------
1 | module.exports = require("nativescript-dev-android-snapshot/hooks/after-prepare-hook.js");
2 |
--------------------------------------------------------------------------------
/demo/hooks/before-prepare/nativescript-dev-android-snapshot.js:
--------------------------------------------------------------------------------
1 | module.exports = require("nativescript-dev-android-snapshot/hooks/before-prepare-hook.js");
2 |
--------------------------------------------------------------------------------
/demo/hooks/before-prepare/nativescript-dev-typescript.js:
--------------------------------------------------------------------------------
1 | module.exports = require("nativescript-dev-typescript/lib/before-prepare.js");
2 |
--------------------------------------------------------------------------------
/demo/hooks/before-watch/nativescript-dev-typescript.js:
--------------------------------------------------------------------------------
1 | module.exports = require("nativescript-dev-typescript/lib/watch.js");
2 |
--------------------------------------------------------------------------------
/demo/livesync.cmd:
--------------------------------------------------------------------------------
1 | @ECHO OFF
2 | CLS
3 |
4 | CALL tns plugin remove nativescript-tasks
5 |
6 | CD ..
7 | CD plugin
8 | ECHO Rebuild plugin...
9 | CALL tsc
10 | CALL tsc -d
11 | ECHO Done
12 |
13 | CD ..
14 | CD demo
15 |
16 | CALL tns plugin add ..\plugin
17 |
18 | CALL tns livesync --watch
19 |
--------------------------------------------------------------------------------
/demo/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "description": "NativeScript Application",
3 | "license": "SEE LICENSE IN ",
4 | "readme": "NativeScript Application",
5 | "repository": "",
6 | "nativescript": {
7 | "id": "org.nativescript.NativeScriptTasksDemo",
8 | "tns-android": {
9 | "version": "2.4.1"
10 | }
11 | },
12 | "dependencies": {
13 | "nativescript-tasks": "file:..\\plugin",
14 | "nativescript-theme-core": "^0.2.1",
15 | "tns-core-modules": "2.4.1"
16 | },
17 | "devDependencies": {
18 | "babel-traverse": "6.19.0",
19 | "babel-types": "6.19.0",
20 | "babylon": "6.14.1",
21 | "lazy": "1.0.11",
22 | "nativescript-dev-android-snapshot": "^0.*.*",
23 | "nativescript-dev-typescript": "^0.3.4",
24 | "typescript": "^2.0.10"
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/demo/references.d.ts:
--------------------------------------------------------------------------------
1 | /// Needed for autocompletion and compilation.
--------------------------------------------------------------------------------
/demo/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "module": "commonjs",
4 | "target": "es5",
5 | "sourceMap": true,
6 | "experimentalDecorators": true,
7 | "emitDecoratorMetadata": true,
8 | "noEmitHelpers": true,
9 | "noEmitOnError": true
10 | },
11 | "exclude": [
12 | "node_modules",
13 | "platforms",
14 | "**/*.aot.ts"
15 | ]
16 | }
--------------------------------------------------------------------------------
/plugin/.npmignore:
--------------------------------------------------------------------------------
1 | *.map
2 | index.ts
3 | tsconfig.json
4 | references.d.ts
--------------------------------------------------------------------------------
/plugin/README.md:
--------------------------------------------------------------------------------
1 | [](https://www.npmjs.com/package/nativescript-tasks)
2 | [](https://www.npmjs.com/package/nativescript-tasks)
3 |
4 | # NativeScript Tasks
5 |
6 | A [NativeScript](https://nativescript.org/) module for simply handling background tasks via web workers.
7 |
8 | [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DE5KRMBB3N2U8)
9 |
10 | ## License
11 |
12 | [MIT license](https://raw.githubusercontent.com/mkloubert/nativescript-tasks/master/LICENSE)
13 |
14 | ## Platforms
15 |
16 | * Android
17 | * iOS
18 |
19 | ## Requirements
20 |
21 | * NativeScript 2.4+ (s. [Multithreading Model](https://docs.nativescript.org/core-concepts/multithreading-model))
22 |
23 | ## Installation
24 |
25 | Run
26 |
27 | ```bash
28 | tns plugin add nativescript-tasks
29 | ```
30 |
31 | inside your app project to install the module.
32 |
33 | ## Example
34 |
35 | ```typescript
36 | import Tasks = require("nativescript-tasks");
37 |
38 | Tasks.startNew((ctx) => {
39 | return 23979 + ctx.state;
40 | },
41 | 5979) // 5979 will be stored in 'state'
42 | // property of 'ctx'
43 | .then((result) => {
44 | console.log('Result: ' + result.data); // 29958
45 | // result.state = 5979
46 | })
47 | .catch((result) => {
48 | console.log('ERROR: ' + result.error);
49 | // result.state = 5979
50 | });
51 | ```
52 |
53 | ## Limitations
54 |
55 | * You can only submit and return serializable objects and values!
56 | * All task functions are 'closures', what means that you CANNOT access variables or modules outside such functions. All functions are serialized as strings and submitted to the [worker script](https://github.com/mkloubert/nativescript-tasks/blob/master/plugin/worker.js) where "external stuff" is NOT available! The only way to share data with the functions is to submit an optional and serializable "state value".
57 |
58 | Read the [official documentation](https://docs.nativescript.org/core-concepts/multithreading-model#limitations) to get more information.
59 |
--------------------------------------------------------------------------------
/plugin/index.d.ts:
--------------------------------------------------------------------------------
1 | import { Observable } from 'data/observable';
2 | /**
3 | * Describes a task function.
4 | *
5 | * @param {TState} [state] The optional value to submit to the function.
6 | *
7 | * @return {TResult} The result of the function.
8 | */
9 | export declare type TaskFunc = (state?: TState) => TResult;
10 | /**
11 | * Describes a task context.
12 | */
13 | export interface TaskContext {
14 | /**
15 | * The optional value that was submitted to the function.
16 | */
17 | state?: TState;
18 | }
19 | /**
20 | * Describes a result of a task.
21 | */
22 | export interface TaskResult {
23 | /**
24 | * The result data (on success)
25 | */
26 | data?: TResult;
27 | /**
28 | * The error (if occurred)
29 | */
30 | error?: any;
31 | /**
32 | * The submitted value.
33 | */
34 | state?: TState;
35 | }
36 | /**
37 | * List of task states.
38 | */
39 | export declare enum TaskStatus {
40 | /**
41 | * The task has been initialized but has not yet been invoked.
42 | */
43 | Created = 0,
44 | /**
45 | * The task completed due to an unhandled exception.
46 | */
47 | Faulted = 1,
48 | /**
49 | * The task completed execution successfully.
50 | */
51 | RanToCompletion = 2,
52 | /**
53 | * The task is running but has not yet completed.
54 | */
55 | Running = 3,
56 | /**
57 | * The task has been scheduled for execution but has not yet begun executing.
58 | */
59 | WaitingToRun = 4,
60 | }
61 | /**
62 | * A task.
63 | */
64 | export declare class Task extends Observable {
65 | /**
66 | * Stores the function to invoke.
67 | */
68 | protected readonly _FUNC: TaskFunc;
69 | /**
70 | * Stores the error of the last execution.
71 | */
72 | protected _error: any;
73 | /**
74 | * Stores the current task state.
75 | */
76 | protected _status: TaskStatus;
77 | /**
78 | * Initializes a new instance of that class.
79 | *
80 | * @param {TaskFunc} func The function to invoke.
81 | */
82 | constructor(func: TaskFunc);
83 | /**
84 | * Gets the error of the last execution.
85 | */
86 | readonly error: any;
87 | /**
88 | * Gets the underyling function to invoke.
89 | */
90 | readonly func: TaskFunc;
91 | /**
92 | * Starts the task.
93 | *
94 | * @param {TState} [state] The optional value to submit to the function.
95 | *
96 | * @return {Promise>} The promise.
97 | */
98 | start(state?: TState): Promise>;
99 | /**
100 | * Gets the current status.
101 | */
102 | readonly status: TaskStatus;
103 | /**
104 | * Updates the error value.
105 | *
106 | * @param {TaskStatus} newValue The new value.
107 | *
108 | * @return {boolean} Property change has been raised for 'error' property or not.
109 | */
110 | protected updateError(newValue: any): boolean;
111 | /**
112 | * Updates the current status.
113 | *
114 | * @param {TaskStatus} newValue The new value.
115 | *
116 | * @return {boolean} Property change has been raised for 'status' property or not.
117 | */
118 | protected updateStatus(newValue: TaskStatus): boolean;
119 | }
120 | /**
121 | * Creates a new task.
122 | *
123 | * @param {TaskFunc} func The function to invoke.
124 | *
125 | * @return {Task} The new task.
126 | */
127 | export declare function newTask(func: TaskFunc): Task;
128 | /**
129 | * Creates and starts a new task.
130 | *
131 | * @param {TaskFunc} func The function to invoke.
132 | * @param {TState} [state] The optional value / object for the execution.
133 | *
134 | * @return {Promise} The promise.
135 | */
136 | export declare function startNew(func: TaskFunc, state?: TState): Promise>;
137 |
--------------------------------------------------------------------------------
/plugin/index.js:
--------------------------------------------------------------------------------
1 | // The MIT License (MIT)
2 | //
3 | // Copyright (c) Marcel Joachim Kloubert
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to
7 | // deal in the Software without restriction, including without limitation the
8 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 | // sell copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 | // DEALINGS IN THE SOFTWARE.
22 | "use strict";
23 | var observable_1 = require('data/observable');
24 | var TypeUtils = require('utils/types');
25 | /**
26 | * List of task states.
27 | */
28 | (function (TaskStatus) {
29 | /**
30 | * The task has been initialized but has not yet been invoked.
31 | */
32 | TaskStatus[TaskStatus["Created"] = 0] = "Created";
33 | /**
34 | * The task completed due to an unhandled exception.
35 | */
36 | TaskStatus[TaskStatus["Faulted"] = 1] = "Faulted";
37 | /**
38 | * The task completed execution successfully.
39 | */
40 | TaskStatus[TaskStatus["RanToCompletion"] = 2] = "RanToCompletion";
41 | /**
42 | * The task is running but has not yet completed.
43 | */
44 | TaskStatus[TaskStatus["Running"] = 3] = "Running";
45 | /**
46 | * The task has been scheduled for execution but has not yet begun executing.
47 | */
48 | TaskStatus[TaskStatus["WaitingToRun"] = 4] = "WaitingToRun";
49 | })(exports.TaskStatus || (exports.TaskStatus = {}));
50 | var TaskStatus = exports.TaskStatus;
51 | /**
52 | * A task.
53 | */
54 | var Task = (function (_super) {
55 | __extends(Task, _super);
56 | /**
57 | * Initializes a new instance of that class.
58 | *
59 | * @param {TaskFunc} func The function to invoke.
60 | */
61 | function Task(func) {
62 | _super.call(this);
63 | if (!TypeUtils.isNullOrUndefined(func)) {
64 | if (typeof func !== "function") {
65 | throw "'func' must be a function!";
66 | }
67 | }
68 | this._FUNC = func;
69 | this.updateStatus(TaskStatus.Created);
70 | }
71 | Object.defineProperty(Task.prototype, "error", {
72 | /**
73 | * Gets the error of the last execution.
74 | */
75 | get: function () {
76 | return this._error;
77 | },
78 | enumerable: true,
79 | configurable: true
80 | });
81 | Object.defineProperty(Task.prototype, "func", {
82 | /**
83 | * Gets the underyling function to invoke.
84 | */
85 | get: function () {
86 | return this._FUNC;
87 | },
88 | enumerable: true,
89 | configurable: true
90 | });
91 | /**
92 | * Starts the task.
93 | *
94 | * @param {TState} [state] The optional value to submit to the function.
95 | *
96 | * @return {Promise>} The promise.
97 | */
98 | Task.prototype.start = function (state) {
99 | var me = this;
100 | return new Promise(function (resolve, reject) {
101 | var completed = function (err, data) {
102 | if (err) {
103 | reject({
104 | error: err,
105 | state: state,
106 | });
107 | }
108 | else {
109 | resolve({
110 | data: data,
111 | state: state,
112 | });
113 | }
114 | me.updateError(err);
115 | };
116 | switch (me._status) {
117 | case TaskStatus.Created:
118 | case TaskStatus.Faulted:
119 | case TaskStatus.RanToCompletion:
120 | break;
121 | default:
122 | completed(new Error("Cannot start while in '" + TaskStatus[me._status] + "' state!"));
123 | return;
124 | }
125 | try {
126 | me.updateStatus(TaskStatus.WaitingToRun);
127 | var worker_1 = new Worker('./worker');
128 | worker_1.onmessage = function (msg) {
129 | worker_1.terminate();
130 | var result = msg.data;
131 | if (result) {
132 | result = JSON.parse(result);
133 | }
134 | me.updateStatus(TaskStatus.RanToCompletion);
135 | completed(null, result);
136 | };
137 | worker_1.onerror = function (err) {
138 | me.updateStatus(TaskStatus.Faulted);
139 | completed(err);
140 | };
141 | var func = void 0;
142 | if (me._FUNC) {
143 | func = {};
144 | var funcStr = '' + me._FUNC;
145 | func.body = funcStr.match(/function[^{]+\{([\s\S]*)\}$/)[1];
146 | // s. https://stackoverflow.com/questions/1007981/how-to-get-function-parameter-names-values-dynamically-from-javascript
147 | //
148 | // author: humbletim (https://stackoverflow.com/users/1684079/humbletim)
149 | func.args = funcStr.replace(/[/][/].*$/mg, '') // strip single-line comments
150 | .replace(/\s+/g, '') // strip white space
151 | .replace(/[/][*][^/*]*[*][/]/g, '') // strip multi-line comments
152 | .split('){', 1)[0].replace(/^[^(]*[(]/, '') // extract the parameters
153 | .replace(/=[^,]+/g, '') // strip any ES6 defaults
154 | .split(',')
155 | .filter(function (x) { return x; }); // remove empty values
156 | }
157 | me.updateStatus(TaskStatus.Running);
158 | worker_1.postMessage(JSON.stringify({
159 | func: func,
160 | state: state,
161 | }));
162 | }
163 | catch (e) {
164 | me.updateStatus(TaskStatus.Faulted);
165 | completed(e);
166 | }
167 | });
168 | };
169 | Object.defineProperty(Task.prototype, "status", {
170 | /**
171 | * Gets the current status.
172 | */
173 | get: function () {
174 | return this._status;
175 | },
176 | enumerable: true,
177 | configurable: true
178 | });
179 | /**
180 | * Updates the error value.
181 | *
182 | * @param {TaskStatus} newValue The new value.
183 | *
184 | * @return {boolean} Property change has been raised for 'error' property or not.
185 | */
186 | Task.prototype.updateError = function (newValue) {
187 | if (newValue !== this._error) {
188 | this._error = newValue;
189 | this.notifyPropertyChange("error", newValue);
190 | return true;
191 | }
192 | return false;
193 | };
194 | /**
195 | * Updates the current status.
196 | *
197 | * @param {TaskStatus} newValue The new value.
198 | *
199 | * @return {boolean} Property change has been raised for 'status' property or not.
200 | */
201 | Task.prototype.updateStatus = function (newValue) {
202 | if (newValue !== this._status) {
203 | this._status = newValue;
204 | this.notifyPropertyChange("status", newValue);
205 | return true;
206 | }
207 | return false;
208 | };
209 | return Task;
210 | }(observable_1.Observable));
211 | exports.Task = Task;
212 | /**
213 | * Creates a new task.
214 | *
215 | * @param {TaskFunc} func The function to invoke.
216 | *
217 | * @return {Task} The new task.
218 | */
219 | function newTask(func) {
220 | return new Task(func);
221 | }
222 | exports.newTask = newTask;
223 | /**
224 | * Creates and starts a new task.
225 | *
226 | * @param {TaskFunc} func The function to invoke.
227 | * @param {TState} [state] The optional value / object for the execution.
228 | *
229 | * @return {Promise} The promise.
230 | */
231 | function startNew(func, state) {
232 | return newTask(func).start(state);
233 | }
234 | exports.startNew = startNew;
235 | //# sourceMappingURL=index.js.map
--------------------------------------------------------------------------------
/plugin/index.ts:
--------------------------------------------------------------------------------
1 | // The MIT License (MIT)
2 | //
3 | // Copyright (c) Marcel Joachim Kloubert
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to
7 | // deal in the Software without restriction, including without limitation the
8 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 | // sell copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 | // DEALINGS IN THE SOFTWARE.
22 |
23 | import { Observable } from 'data/observable';
24 | import TypeUtils = require('utils/types');
25 |
26 | /**
27 | * Describes a task function.
28 | *
29 | * @param {TState} [state] The optional value to submit to the function.
30 | *
31 | * @return {TResult} The result of the function.
32 | */
33 | export type TaskFunc = (state?: TState) => TResult;
34 |
35 | /**
36 | * Describes a task context.
37 | */
38 | export interface TaskContext {
39 | /**
40 | * The optional value that was submitted to the function.
41 | */
42 | state?: TState;
43 | }
44 |
45 | /**
46 | * Describes a result of a task.
47 | */
48 | export interface TaskResult {
49 | /**
50 | * The result data (on success)
51 | */
52 | data?: TResult;
53 |
54 | /**
55 | * The error (if occurred)
56 | */
57 | error?: any;
58 |
59 | /**
60 | * The submitted value.
61 | */
62 | state?: TState;
63 | }
64 |
65 | /**
66 | * List of task states.
67 | */
68 | export enum TaskStatus {
69 | /**
70 | * The task has been initialized but has not yet been invoked.
71 | */
72 | Created,
73 |
74 | /**
75 | * The task completed due to an unhandled exception.
76 | */
77 | Faulted,
78 |
79 | /**
80 | * The task completed execution successfully.
81 | */
82 | RanToCompletion,
83 |
84 | /**
85 | * The task is running but has not yet completed.
86 | */
87 | Running,
88 |
89 | /**
90 | * The task has been scheduled for execution but has not yet begun executing.
91 | */
92 | WaitingToRun,
93 | }
94 |
95 | /**
96 | * A task.
97 | */
98 | export class Task extends Observable {
99 | /**
100 | * Stores the function to invoke.
101 | */
102 | protected readonly _FUNC: TaskFunc;
103 | /**
104 | * Stores the error of the last execution.
105 | */
106 | protected _error: any;
107 | /**
108 | * Stores the current task state.
109 | */
110 | protected _status: TaskStatus;
111 |
112 | /**
113 | * Initializes a new instance of that class.
114 | *
115 | * @param {TaskFunc} func The function to invoke.
116 | */
117 | constructor(func: TaskFunc) {
118 | super();
119 |
120 | if (!TypeUtils.isNullOrUndefined(func)) {
121 | if (typeof func !== "function") {
122 | throw "'func' must be a function!";
123 | }
124 | }
125 |
126 | this._FUNC = func;
127 |
128 | this.updateStatus(TaskStatus.Created);
129 | }
130 |
131 | /**
132 | * Gets the error of the last execution.
133 | */
134 | public get error(): any {
135 | return this._error;
136 | }
137 |
138 | /**
139 | * Gets the underyling function to invoke.
140 | */
141 | public get func(): TaskFunc {
142 | return this._FUNC;
143 | }
144 |
145 | /**
146 | * Starts the task.
147 | *
148 | * @param {TState} [state] The optional value to submit to the function.
149 | *
150 | * @return {Promise>} The promise.
151 | */
152 | public start(state?: TState): Promise> {
153 | let me = this;
154 |
155 | return new Promise>((resolve, reject) => {
156 | let completed = (err: any, data?: TResult) => {
157 | if (err) {
158 | reject({
159 | error: err,
160 | state: state,
161 | });
162 | }
163 | else {
164 | resolve({
165 | data: data,
166 | state: state,
167 | });
168 | }
169 |
170 | me.updateError(err);
171 | };
172 |
173 | switch (me._status) {
174 | case TaskStatus.Created:
175 | case TaskStatus.Faulted:
176 | case TaskStatus.RanToCompletion:
177 | break;
178 |
179 | default:
180 | completed(new Error(`Cannot start while in '${TaskStatus[me._status]}' state!`));
181 | return;
182 | }
183 |
184 | try {
185 | me.updateStatus(TaskStatus.WaitingToRun);
186 |
187 | let worker = new Worker('./worker');
188 |
189 | worker.onmessage = function(msg) {
190 | worker.terminate();
191 |
192 | let result = msg.data;
193 | if (result) {
194 | result = JSON.parse(result);
195 | }
196 |
197 | me.updateStatus(TaskStatus.RanToCompletion);
198 | completed(null, result);
199 | };
200 |
201 | worker.onerror = function(err) {
202 | me.updateStatus(TaskStatus.Faulted);
203 |
204 | completed(err);
205 | };
206 |
207 | let func: any;
208 | if (me._FUNC) {
209 | func = {};
210 |
211 | let funcStr = '' + me._FUNC;
212 |
213 | func.body = funcStr.match(/function[^{]+\{([\s\S]*)\}$/)[1];
214 |
215 | // s. https://stackoverflow.com/questions/1007981/how-to-get-function-parameter-names-values-dynamically-from-javascript
216 | //
217 | // author: humbletim (https://stackoverflow.com/users/1684079/humbletim)
218 | func.args = funcStr.replace(/[/][/].*$/mg,'') // strip single-line comments
219 | .replace(/\s+/g, '') // strip white space
220 | .replace(/[/][*][^/*]*[*][/]/g, '') // strip multi-line comments
221 | .split('){', 1)[0].replace(/^[^(]*[(]/, '') // extract the parameters
222 | .replace(/=[^,]+/g, '') // strip any ES6 defaults
223 | .split(',')
224 | .filter(x => x); // remove empty values
225 | }
226 |
227 | me.updateStatus(TaskStatus.Running);
228 | worker.postMessage(JSON.stringify({
229 | func: func,
230 | state: state,
231 | }));
232 | }
233 | catch (e) {
234 | me.updateStatus(TaskStatus.Faulted);
235 |
236 | completed(e);
237 | }
238 | });
239 | }
240 |
241 | /**
242 | * Gets the current status.
243 | */
244 | public get status(): TaskStatus {
245 | return this._status;
246 | }
247 |
248 | /**
249 | * Updates the error value.
250 | *
251 | * @param {TaskStatus} newValue The new value.
252 | *
253 | * @return {boolean} Property change has been raised for 'error' property or not.
254 | */
255 | protected updateError(newValue: any): boolean {
256 | if (newValue !== this._error) {
257 | this._error = newValue;
258 |
259 | this.notifyPropertyChange("error", newValue);
260 | return true;
261 | }
262 |
263 | return false;
264 | }
265 |
266 | /**
267 | * Updates the current status.
268 | *
269 | * @param {TaskStatus} newValue The new value.
270 | *
271 | * @return {boolean} Property change has been raised for 'status' property or not.
272 | */
273 | protected updateStatus(newValue: TaskStatus): boolean {
274 | if (newValue !== this._status) {
275 | this._status = newValue;
276 |
277 | this.notifyPropertyChange("status", newValue);
278 | return true;
279 | }
280 |
281 | return false;
282 | }
283 | }
284 |
285 | /**
286 | * Creates a new task.
287 | *
288 | * @param {TaskFunc} func The function to invoke.
289 | *
290 | * @return {Task} The new task.
291 | */
292 | export function newTask(func: TaskFunc): Task {
293 | return new Task(func);
294 | }
295 |
296 | /**
297 | * Creates and starts a new task.
298 | *
299 | * @param {TaskFunc} func The function to invoke.
300 | * @param {TState} [state] The optional value / object for the execution.
301 | *
302 | * @return {Promise} The promise.
303 | */
304 | export function startNew(func: TaskFunc, state?: TState): Promise> {
305 | return newTask(func).start(state);
306 | }
307 |
--------------------------------------------------------------------------------
/plugin/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nativescript-tasks",
3 | "description": "NativeScript module for simply invoking and handling background tasks via web workers.",
4 | "version": "1.0.8",
5 | "nativescript": {
6 | "platforms": {
7 | "android": "1.1.0",
8 | "ios": "1.0.0"
9 | }
10 | },
11 | "repository": {
12 | "type": "git",
13 | "url": "https://github.com/mkloubert/nativescript-tasks"
14 | },
15 | "keywords": [
16 | "NativeScript",
17 | "Web",
18 | "Workers",
19 | "Webworkers",
20 | "Tasking",
21 | "Tasks",
22 | "Multi",
23 | "Multitasking",
24 | "Threading",
25 | "Threads",
26 | "Background"
27 | ],
28 | "author": {
29 | "name": "Marcel Joachim Kloubert",
30 | "email": "marcel.kloubert@gmx.net"
31 | },
32 | "license": {
33 | "type": "MIT",
34 | "url": "https://github.com/mkloubert/nativescript-tasks/blob/master/LICENSE"
35 | },
36 | "bugs": {
37 | "url": "https://github.com/mkloubert/nativescript-tasks/issues"
38 | },
39 | "homepage": "https://github.com/mkloubert/nativescript-tasks",
40 | "readmeFilename": "README.md"
41 | }
42 |
--------------------------------------------------------------------------------
/plugin/references.d.ts:
--------------------------------------------------------------------------------
1 | /// Enable smart suggestions and completions in Visual Studio Code JavaScript projects.
2 |
--------------------------------------------------------------------------------
/plugin/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "module": "commonjs",
4 | "target": "es5",
5 | "sourceMap": true,
6 | "experimentalDecorators": true,
7 | "emitDecoratorMetadata": true,
8 | "noEmitHelpers": true,
9 | "noEmitOnError": true
10 | }
11 | }
--------------------------------------------------------------------------------
/plugin/worker.js:
--------------------------------------------------------------------------------
1 | // The MIT License (MIT)
2 | //
3 | // Copyright (c) Marcel Joachim Kloubert
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to
7 | // deal in the Software without restriction, including without limitation the
8 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 | // sell copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 | // DEALINGS IN THE SOFTWARE.
22 |
23 | require('globals');
24 |
25 | onmessage = function(msg) {
26 | var request = JSON.parse(msg.data);
27 |
28 | var func;
29 | if (request.func) {
30 | eval('func = function(' + request.func.args.join(', ') + ') { ' + request.func.body + ' };');
31 | }
32 |
33 | var result;
34 | if (func) {
35 | result = func({
36 | state: request.state,
37 | });
38 | }
39 |
40 | if (result) {
41 | result = JSON.stringify(result);
42 | }
43 |
44 | postMessage(result);
45 | }
46 | exports.onmessage = onmessage;
47 |
--------------------------------------------------------------------------------