@maccesar/titools 2.2.3 → 2.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -27
- package/lib/commands/update.js +80 -101
- package/package.json +1 -1
- package/skills/alloy-guides/SKILL.md +31 -31
- package/skills/alloy-guides/references/CONCEPTS.md +3 -3
- package/skills/alloy-guides/references/CONTROLLERS.md +1 -1
- package/skills/alloy-guides/references/MODELS.md +6 -6
- package/skills/alloy-guides/references/VIEWS_WITHOUT_CONTROLLERS.md +1 -1
- package/skills/alloy-guides/references/VIEWS_XML.md +1 -1
- package/skills/alloy-guides/references/WIDGETS.md +1 -1
- package/skills/alloy-howtos/SKILL.md +27 -27
- package/skills/alloy-howtos/references/best_practices.md +9 -9
- package/skills/alloy-howtos/references/cli_reference.md +14 -14
- package/skills/alloy-howtos/references/config_files.md +16 -16
- package/skills/alloy-howtos/references/custom_tags.md +16 -16
- package/skills/alloy-howtos/references/debugging_troubleshooting.md +11 -15
- package/skills/alloy-howtos/references/samples.md +19 -19
- package/skills/purgetss/SKILL.md +11 -1
- package/skills/purgetss/references/animation-system.md +1 -1
- package/skills/purgetss/references/cli-commands.md +3 -3
- package/skills/purgetss/references/customization-deep-dive.md +1 -1
- package/skills/purgetss/references/dynamic-component-creation.md +1 -1
- package/skills/purgetss/references/icon-fonts.md +4 -0
- package/skills/purgetss/references/installation-setup.md +8 -1
- package/skills/purgetss/references/migration-guide.md +4 -0
- package/skills/purgetss/references/tikit-components.md +193 -204
- package/skills/purgetss/references/ui-ux-design.md +1 -1
- package/skills/ti-expert/SKILL.md +78 -118
- package/skills/ti-expert/references/alloy-builtins.md +18 -18
- package/skills/ti-expert/references/alloy-structure.md +21 -21
- package/skills/ti-expert/references/anti-patterns.md +15 -15
- package/skills/ti-expert/references/cli-expert.md +15 -15
- package/skills/ti-expert/references/code-conventions.md +38 -38
- package/skills/ti-expert/references/contracts.md +8 -8
- package/skills/ti-expert/references/controller-patterns.md +14 -14
- package/skills/ti-expert/references/error-handling.md +11 -11
- package/skills/ti-expert/references/examples.md +12 -12
- package/skills/ti-expert/references/migration-patterns.md +24 -24
- package/skills/ti-expert/references/patterns.md +10 -10
- package/skills/ti-expert/references/performance-listview.md +16 -16
- package/skills/ti-expert/references/performance-optimization.md +41 -41
- package/skills/ti-expert/references/security-device.md +22 -22
- package/skills/ti-expert/references/security-fundamentals.md +19 -19
- package/skills/ti-expert/references/state-management.md +33 -33
- package/skills/ti-expert/references/testing-e2e-ci.md +25 -25
- package/skills/ti-expert/references/testing-unit.md +24 -24
- package/skills/ti-expert/references/theming.md +15 -15
- package/skills/ti-guides/SKILL.md +58 -60
- package/skills/ti-guides/references/advanced-data-and-images.md +33 -33
- package/skills/ti-guides/references/android-manifest.md +15 -15
- package/skills/ti-guides/references/app-distribution.md +70 -166
- package/skills/ti-guides/references/application-frameworks.md +96 -114
- package/skills/ti-guides/references/cli-reference.md +294 -294
- package/skills/ti-guides/references/coding-best-practices.md +42 -33
- package/skills/ti-guides/references/commonjs-advanced.md +57 -51
- package/skills/ti-guides/references/hello-world.md +36 -36
- package/skills/ti-guides/references/hyperloop-native-access.md +66 -66
- package/skills/ti-guides/references/javascript-primer.md +83 -101
- package/skills/ti-guides/references/reserved-words.md +9 -9
- package/skills/ti-guides/references/resources.md +75 -83
- package/skills/ti-guides/references/style-and-conventions.md +35 -28
- package/skills/ti-guides/references/tiapp-config.md +110 -74
- package/skills/ti-howtos/SKILL.md +88 -92
- package/skills/ti-howtos/references/android-platform-deep-dives.md +104 -104
- package/skills/ti-howtos/references/automation-fastlane-appium.md +39 -39
- package/skills/ti-howtos/references/buffer-codec-streams.md +60 -60
- package/skills/ti-howtos/references/cross-platform-development.md +115 -136
- package/skills/ti-howtos/references/debugging-profiling.md +167 -181
- package/skills/ti-howtos/references/extending-titanium.md +121 -121
- package/skills/ti-howtos/references/google-maps-v2.md +84 -82
- package/skills/ti-howtos/references/ios-map-kit.md +65 -60
- package/skills/ti-howtos/references/ios-platform-deep-dives.md +123 -123
- package/skills/ti-howtos/references/local-data-sources.md +79 -78
- package/skills/ti-howtos/references/location-and-maps.md +116 -120
- package/skills/ti-howtos/references/media-apis.md +87 -86
- package/skills/ti-howtos/references/notification-services.md +250 -260
- package/skills/ti-howtos/references/remote-data-sources.md +98 -93
- package/skills/ti-howtos/references/tutorials.md +226 -216
- package/skills/ti-howtos/references/using-modules.md +73 -102
- package/skills/ti-howtos/references/web-content-integration.md +101 -103
- package/skills/ti-howtos/references/webpack-build-pipeline.md +52 -44
- package/skills/ti-ui/SKILL.md +85 -85
- package/skills/ti-ui/references/accessibility-deep-dive.md +57 -57
- package/skills/ti-ui/references/animation-and-matrices.md +79 -79
- package/skills/ti-ui/references/application-structures.md +96 -99
- package/skills/ti-ui/references/custom-fonts-styling.md +99 -99
- package/skills/ti-ui/references/event-handling.md +58 -58
- package/skills/ti-ui/references/gestures.md +62 -64
- package/skills/ti-ui/references/icons-and-splash-screens.md +88 -88
- package/skills/ti-ui/references/layouts-and-positioning.md +87 -97
- package/skills/ti-ui/references/listviews-and-performance.md +107 -107
- package/skills/ti-ui/references/orientation.md +87 -88
- package/skills/ti-ui/references/platform-ui-android.md +87 -81
- package/skills/ti-ui/references/platform-ui-ios.md +63 -61
- package/skills/ti-ui/references/scrolling-views.md +29 -29
- package/skills/ti-ui/references/tableviews.md +56 -56
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
# Local
|
|
1
|
+
# Local data sources
|
|
2
2
|
|
|
3
|
-
## 1. Filesystem
|
|
3
|
+
## 1. Filesystem access and storage
|
|
4
4
|
|
|
5
|
-
### Modules
|
|
6
|
-
- `Ti.Filesystem` -
|
|
7
|
-
- `Ti.Filesystem.File` -
|
|
8
|
-
- `Ti.Filesystem.FileStream` -
|
|
5
|
+
### Modules overview
|
|
6
|
+
- `Ti.Filesystem` - top-level module for file/directory operations
|
|
7
|
+
- `Ti.Filesystem.File` - file object with read/write methods
|
|
8
|
+
- `Ti.Filesystem.FileStream` - stream wrapper implementing `Ti.IOStream`
|
|
9
9
|
|
|
10
|
-
### Storage
|
|
10
|
+
### Storage locations
|
|
11
11
|
|
|
12
12
|
| Location | Read/Write | Persistence | Notes |
|
|
13
13
|
| --------------------------- | ---------- | ---------------- | -------------------------------------- |
|
|
14
14
|
| `applicationDataDirectory` | R/W | Until uninstall | Primary app data location |
|
|
15
|
-
| `resourcesDirectory` | R-only | Until uninstall | App resources (R/W in simulator only
|
|
15
|
+
| `resourcesDirectory` | R-only | Until uninstall | App resources (R/W in simulator only) |
|
|
16
16
|
| `tempDirectory` | R/W | Until app closes | OS may delete anytime |
|
|
17
17
|
| `applicationCacheDirectory` | R/W | OS may clean | For cached data |
|
|
18
18
|
| `externalCacheDirectory` | R/W | OS may clean | Android SD card cache |
|
|
19
19
|
| `externalStorageDirectory` | R/W | Until uninstall | Android SD card storage |
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
Always check `Ti.Filesystem.isExternalStoragePresent()` before using external storage on Android.
|
|
22
22
|
|
|
23
|
-
### File
|
|
23
|
+
### File operations
|
|
24
24
|
|
|
25
|
-
#### Getting a
|
|
25
|
+
#### Getting a file handle
|
|
26
26
|
```javascript
|
|
27
27
|
const f = Ti.Filesystem.getFile(
|
|
28
28
|
Ti.Filesystem.applicationDataDirectory,
|
|
@@ -30,24 +30,24 @@ const f = Ti.Filesystem.getFile(
|
|
|
30
30
|
);
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
#### Writing
|
|
33
|
+
#### Writing files
|
|
34
34
|
```javascript
|
|
35
|
-
f.write('Content here');
|
|
35
|
+
f.write('Content here'); // Overwrites or creates
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
#### Reading
|
|
38
|
+
#### Reading files
|
|
39
39
|
```javascript
|
|
40
|
-
const contents = f.read();
|
|
41
|
-
Ti.API.info(contents.text);
|
|
42
|
-
Ti.API.info(contents.mimeType);
|
|
40
|
+
const contents = f.read(); // Returns Blob
|
|
41
|
+
Ti.API.info(contents.text); // Text content
|
|
42
|
+
Ti.API.info(contents.mimeType); // MIME type
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
#### Appending
|
|
46
46
|
```javascript
|
|
47
|
-
f.append('More content\n');
|
|
47
|
+
f.append('More content\n'); // String, Blob, or File
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
#### Creating/
|
|
50
|
+
#### Creating/copying
|
|
51
51
|
```javascript
|
|
52
52
|
// Auto-creates on write, but explicit option exists:
|
|
53
53
|
if (!f.exists()) {
|
|
@@ -64,7 +64,7 @@ newFile.write(oldFile.read());
|
|
|
64
64
|
```
|
|
65
65
|
|
|
66
66
|
#### Renaming
|
|
67
|
-
|
|
67
|
+
Important: the file handle still points to the old name after rename.
|
|
68
68
|
|
|
69
69
|
```javascript
|
|
70
70
|
const f = Ti.Filesystem.getFile(applicationDataDirectory, 'old.txt');
|
|
@@ -76,11 +76,11 @@ const newf = Ti.Filesystem.getFile(applicationDataDirectory, 'new.txt');
|
|
|
76
76
|
#### Deleting
|
|
77
77
|
```javascript
|
|
78
78
|
if (f.exists() && f.writable) {
|
|
79
|
-
const success = f.deleteFile();
|
|
79
|
+
const success = f.deleteFile(); // Returns Boolean, no error thrown
|
|
80
80
|
}
|
|
81
81
|
```
|
|
82
82
|
|
|
83
|
-
### Directory
|
|
83
|
+
### Directory operations
|
|
84
84
|
|
|
85
85
|
```javascript
|
|
86
86
|
// Create directory
|
|
@@ -95,16 +95,16 @@ const file = Ti.Filesystem.getFile(applicationDataDirectory, 'file.txt');
|
|
|
95
95
|
file.move('mysubdir/file.txt');
|
|
96
96
|
|
|
97
97
|
// Delete directory (must be empty or force recursive)
|
|
98
|
-
dir.deleteDirectory(false);
|
|
99
|
-
dir.deleteDirectory(true);
|
|
98
|
+
dir.deleteDirectory(false); // Fails if not empty
|
|
99
|
+
dir.deleteDirectory(true); // Recursive delete
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
-
### Case
|
|
103
|
-
Android and Mobile Web use case-sensitive filesystems. File names referenced in code must match actual file names exactly. Recommendation:
|
|
102
|
+
### Case sensitivity warning
|
|
103
|
+
Android and Mobile Web use case-sensitive filesystems. File names referenced in code must match actual file names exactly. Recommendation: use lowercase file names.
|
|
104
104
|
|
|
105
|
-
## 2. SQLite
|
|
105
|
+
## 2. SQLite database
|
|
106
106
|
|
|
107
|
-
### Installing a
|
|
107
|
+
### Installing a pre-populated database
|
|
108
108
|
Ship a database with your app and install it on first launch:
|
|
109
109
|
```javascript
|
|
110
110
|
// Copies db from Resources/ (or app/assets/) to applicationDataDirectory
|
|
@@ -112,7 +112,7 @@ const db = Ti.Database.install('seeds/mydata.sqlite', 'mydata');
|
|
|
112
112
|
// On subsequent launches, install() just opens the existing database
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
-
### Opening
|
|
115
|
+
### Opening databases
|
|
116
116
|
|
|
117
117
|
```javascript
|
|
118
118
|
// Install (copies from Resources if first time)
|
|
@@ -129,39 +129,39 @@ const dbFile = Ti.Filesystem.getFile(
|
|
|
129
129
|
const db = Ti.Database.open(dbFile.nativePath);
|
|
130
130
|
```
|
|
131
131
|
|
|
132
|
-
### Querying
|
|
132
|
+
### Querying data
|
|
133
133
|
|
|
134
134
|
```javascript
|
|
135
135
|
const rows = db.execute('SELECT * FROM users WHERE age > ?', [18]);
|
|
136
136
|
|
|
137
137
|
while (rows.isValidRow()) {
|
|
138
138
|
Ti.API.info(rows.fieldByName('name'));
|
|
139
|
-
Ti.API.info(rows.field(0));
|
|
139
|
+
Ti.API.info(rows.field(0)); // First column by index
|
|
140
140
|
rows.next();
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
//
|
|
143
|
+
// Always close result set
|
|
144
144
|
rows.close();
|
|
145
145
|
```
|
|
146
146
|
|
|
147
|
-
### Parameterized
|
|
147
|
+
### Parameterized queries
|
|
148
148
|
Always use parameters to prevent SQL injection:
|
|
149
149
|
|
|
150
150
|
```javascript
|
|
151
|
-
//
|
|
151
|
+
// Safe - parameterized
|
|
152
152
|
db.execute('INSERT INTO users (name, age) VALUES (?, ?)', ['John', 25]);
|
|
153
153
|
|
|
154
|
-
//
|
|
154
|
+
// Unsafe - never do this
|
|
155
155
|
db.execute(`INSERT INTO users (name, age) VALUES ('${name}', ${age})`);
|
|
156
156
|
```
|
|
157
157
|
|
|
158
|
-
### Data
|
|
158
|
+
### Data modification
|
|
159
159
|
|
|
160
160
|
```javascript
|
|
161
161
|
// INSERT
|
|
162
162
|
db.execute('INSERT INTO users (name, age) VALUES (?, ?)', ['Jane', 30]);
|
|
163
|
-
const lastId = db.lastInsertRowId;
|
|
164
|
-
const affected = db.rowsAffected;
|
|
163
|
+
const lastId = db.lastInsertRowId; // ID of the last inserted row
|
|
164
|
+
const affected = db.rowsAffected; // number of rows changed by last statement
|
|
165
165
|
|
|
166
166
|
// UPDATE
|
|
167
167
|
db.execute('UPDATE users SET age = ? WHERE name = ?', [31, 'Jane']);
|
|
@@ -171,42 +171,43 @@ const rowsAffected = db.rowsAffected;
|
|
|
171
171
|
db.execute('DELETE FROM users WHERE age < ?', [18]);
|
|
172
172
|
```
|
|
173
173
|
|
|
174
|
-
### Transactions for
|
|
175
|
-
Use transactions to
|
|
174
|
+
### Transactions for batch operations
|
|
175
|
+
Use transactions to speed up multiple inserts or updates:
|
|
176
176
|
```javascript
|
|
177
177
|
const db = Ti.Database.open('mydb');
|
|
178
178
|
db.execute('BEGIN');
|
|
179
179
|
try {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
180
|
+
for (let i = 0; i < items.length; i++) {
|
|
181
|
+
db.execute('INSERT INTO products (name, price) VALUES (?, ?)', items[i].name, items[i].price);
|
|
182
|
+
}
|
|
183
|
+
db.execute('COMMIT');
|
|
184
184
|
} catch (e) {
|
|
185
|
-
|
|
186
|
-
|
|
185
|
+
db.execute('ROLLBACK');
|
|
186
|
+
Ti.API.error(`Transaction failed: ${e.message}`);
|
|
187
187
|
}
|
|
188
188
|
db.close();
|
|
189
189
|
```
|
|
190
190
|
|
|
191
|
-
|
|
191
|
+
Performance: wrapping 1000 inserts in a transaction can be 10-100x faster than individual inserts.
|
|
192
192
|
|
|
193
|
-
### SQLite
|
|
194
|
-
- No `FULL OUTER JOIN` support
|
|
195
|
-
- Limited `ALTER TABLE
|
|
196
|
-
- No built-in referential integrity (foreign
|
|
197
|
-
- No native boolean type
|
|
193
|
+
### SQLite limitations
|
|
194
|
+
- No `FULL OUTER JOIN` support. Use `LEFT JOIN` with `UNION`.
|
|
195
|
+
- Limited `ALTER TABLE`. You can only `ADD COLUMN` or `RENAME TABLE`.
|
|
196
|
+
- No built-in referential integrity (foreign keys). Enable with `PRAGMA foreign_keys = ON`.
|
|
197
|
+
- No native boolean type. Use INTEGER (0/1).
|
|
198
198
|
|
|
199
|
-
### Disable iCloud
|
|
200
|
-
|
|
199
|
+
### Disable iCloud backup for databases (iOS)
|
|
200
|
+
|
|
201
|
+
iOS backs up databases to iCloud by default. For large or recreatable databases, disable this:
|
|
201
202
|
```javascript
|
|
202
203
|
const db = Ti.Database.open('mydb');
|
|
203
204
|
db.file.setRemoteBackup(false);
|
|
204
205
|
db.close();
|
|
205
206
|
```
|
|
206
207
|
|
|
207
|
-
|
|
208
|
+
Important: Apple may reject apps that back up large recreatable data to iCloud.
|
|
208
209
|
|
|
209
|
-
###
|
|
210
|
+
### Always close connections
|
|
210
211
|
|
|
211
212
|
```javascript
|
|
212
213
|
try {
|
|
@@ -223,11 +224,11 @@ try {
|
|
|
223
224
|
### Overview
|
|
224
225
|
Lightweight key-value storage for simple data types. Loaded into memory at launch for fast access.
|
|
225
226
|
|
|
226
|
-
|
|
227
|
+
Warning: there is no hard limit, but all properties load into memory. Avoid storing large data.
|
|
227
228
|
|
|
228
|
-
### Data
|
|
229
|
+
### Data type methods
|
|
229
230
|
|
|
230
|
-
| Type | Get
|
|
231
|
+
| Type | Get method | Set method |
|
|
231
232
|
| ------ | -------------------------- | ------------------------ |
|
|
232
233
|
| String | `getString(name, default)` | `setString(name, value)` |
|
|
233
234
|
| Int | `getInt(name, default)` | `setInt(name, value)` |
|
|
@@ -235,7 +236,7 @@ Lightweight key-value storage for simple data types. Loaded into memory at launc
|
|
|
235
236
|
| Bool | `getBool(name, default)` | `setBool(name, value)` |
|
|
236
237
|
| List | `getList(name, default)` | `setList(name, value)` |
|
|
237
238
|
|
|
238
|
-
### Usage
|
|
239
|
+
### Usage examples
|
|
239
240
|
|
|
240
241
|
```javascript
|
|
241
242
|
// Set values
|
|
@@ -261,7 +262,7 @@ Ti.App.Properties.removeProperty('username');
|
|
|
261
262
|
const allProps = Ti.App.Properties.listProperties();
|
|
262
263
|
```
|
|
263
264
|
|
|
264
|
-
### Storing
|
|
265
|
+
### Storing complex objects as JSON
|
|
265
266
|
|
|
266
267
|
```javascript
|
|
267
268
|
// Store object as JSON string
|
|
@@ -271,24 +272,24 @@ Ti.App.Properties.setString('weatherData', JSON.stringify(data));
|
|
|
271
272
|
// Retrieve and parse
|
|
272
273
|
const stored = Ti.App.Properties.getString('weatherData', '{}');
|
|
273
274
|
const weather = JSON.parse(stored);
|
|
274
|
-
Ti.API.info(weather.city);
|
|
275
|
+
Ti.API.info(weather.city); // 'Mountain View'
|
|
275
276
|
```
|
|
276
277
|
|
|
277
|
-
### Platform
|
|
278
|
-
-
|
|
279
|
-
-
|
|
278
|
+
### Platform storage
|
|
279
|
+
- iOS: `NSUserDefaults` in a `.plist` file
|
|
280
|
+
- Android: XML file at `/data/data/com.domain.app/shared_prefs/titanium.xml`
|
|
280
281
|
|
|
281
|
-
## 4. Advanced
|
|
282
|
+
## 4. Advanced data manipulation (Buffer, Codec, and Streams)
|
|
282
283
|
|
|
283
|
-
For binary data handling, character encoding, and large file streams,
|
|
284
|
+
For binary data handling, character encoding, and large file streams, see:
|
|
284
285
|
|
|
285
|
-
-
|
|
286
|
+
- Buffer, Codec, and Streams: `buffer-codec-streams.md`
|
|
286
287
|
|
|
287
|
-
## 5. Choosing a
|
|
288
|
+
## 5. Choosing a persistence strategy
|
|
288
289
|
|
|
289
|
-
### Decision
|
|
290
|
+
### Decision guide
|
|
290
291
|
|
|
291
|
-
| Scenario | Recommended
|
|
292
|
+
| Scenario | Recommended approach |
|
|
292
293
|
| ---------------------------------- | ---------------------------------------- |
|
|
293
294
|
| User settings/preferences | `Ti.App.Properties` |
|
|
294
295
|
| Small config data (< 100KB) | `Ti.App.Properties` with JSON |
|
|
@@ -299,11 +300,11 @@ For binary data handling, character encoding, and large file streams, refer to t
|
|
|
299
300
|
| User-generated files | Filesystem (`applicationDataDirectory`) |
|
|
300
301
|
| Offline-first app data | SQLite + Filesystem combo |
|
|
301
302
|
|
|
302
|
-
### Best
|
|
303
|
+
### Best practices
|
|
303
304
|
|
|
304
|
-
1.
|
|
305
|
-
2.
|
|
306
|
-
3.
|
|
307
|
-
4.
|
|
308
|
-
5.
|
|
309
|
-
6.
|
|
305
|
+
1. Properties API: use only for small, frequently accessed config data.
|
|
306
|
+
2. SQLite: always close connections and result sets; use parameterized queries.
|
|
307
|
+
3. Filesystem: check external storage availability on Android; handle case sensitivity.
|
|
308
|
+
4. Streams: use for large file operations to avoid memory issues.
|
|
309
|
+
5. Hybrid approach: store metadata in SQLite, file paths in records, actual files on filesystem.
|
|
310
|
+
6. Cleanup: implement cleanup for temp files and cache; do not let them accumulate.
|