GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||
GeezerVison is showing github.com — RFC: declarative app preferences by sitefinitysteve · Pull Request #54 · NativeScript/rfcs Conversation
|
There was an error while loading. Please reload this page.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I just THINK... having a proper preferences story in the project that's supported and polished instead of just "Store some crap as strings in a generic ApplicationSettings object" (not that you still can't) is just NICER to be a core feature. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
354c569 to
6b22f52
Compare
|
I feel like authoring the definition in TypeScript would be a nice approach, fully typed, and could directly serve as the runtime types too. Something like // src/app.preferences.ts (or wherever) import { definePreferences } from "@nativescript/preferences"; export default definePreferences({ /* ... */ }); The Usage becomes: import settings from './app.preferences'; settings.get('theme'); // 'system' | 'light' | 'dark', never undefined settings.set('volume', 80); // NSUserDefaults / SharedPreferences settings.set('enabled', 'yes'); // compile error settings.onChange('theme', applyTheme); await settings.openSettings(); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Settings are declared in app/app.preferences.ts as
`export default definePreferences({ items })`. Keys and value types are
inferred from the literal and the default export is the typed instance, so
there is no generated settings.generated.ts any more. The before-prepare
hook evaluates the same file under Node with ts.transpileModule, the way
the CLI reads nativescript.config.ts, and writes Settings.bundle and
preferences.xml from it as before. preferences.json keeps working.
Requires TypeScript 5.3 or newer for the typings (verified through 7.0).
TypeScript 7 no longer ships the compiler API, so the loader falls back to
the NativeScript CLI's own typescript when the project's cannot transpile.
Demo moved to app/app.preferences.ts; its native output is byte-identical
to the JSON version. Also pins decode-uri-component 0.5 in the demo.
Suggested by the core team on the RFC:
NativeScript/rfcs#54 (comment)
Per review: the settings are declared in app/app.preferences.ts with definePreferences, which infers the keys and value types and is the runtime instance, so no TypeScript module is generated. The hook reads the file under Node the way the CLI reads nativescript.config.ts. preferences.json stays supported. Implemented in nativescript-preferences 3.0.
I JUST upgraded it from the dated plugin years ago, easy swap, it's checked in per your notes, runs fine on both sims https://github.com/sitefinitysteve/nativescript-preferences/releases/tag/v2.1.0 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.