NativeScript for Mobile App Development State Management and Application Architecture 1 — Questions and Answers
Question 1: Which NativeScript class is the base class for all observable objects used in state management?
- EventEmitter
- Observable (Correct answer)
- BindingContext
- Store
Correct answer: Observable
Observable is NativeScript's built-in base class that enables property-change notifications used for data binding and state management.
Question 2: In NativeScript with Angular, which pattern is recommended for sharing state across multiple components?
- Component Input/Output
- Local Storage binding
- Injectable singleton services (Correct answer)
- Route query parameters
Correct answer: Injectable singleton services
Injectable singleton services (provided in 'root') act as centralized state containers accessible across all components in a NativeScript Angular app.
Question 3: What method on an Observable object is used to notify listeners when a property value changes?
- emit()
- dispatch()
- notifyPropertyChange() (Correct answer)
- setState()
Correct answer: notifyPropertyChange()
notifyPropertyChange() triggers the propertyChange event on an Observable, informing bound UI elements and listeners about state updates.
Question 4: When using NativeScript with Vue.js, which state management library is most commonly adopted for global state?
- Redux
- Vuex (Correct answer)
- MobX
- Akita
Correct answer: Vuex
Vuex is Vue's official state management library and integrates naturally with NativeScript-Vue applications for centralized store management.
Question 5: What is the purpose of the 'bindingContext' property in a NativeScript page or component?
- It sets the page's CSS theme
- It defines the data source for two-way data binding (Correct answer)
- It registers event listeners
- It specifies the navigation history
Correct answer: It defines the data source for two-way data binding
bindingContext defines the object whose properties are accessible for data binding expressions within that page or component's template.
Question 6: In a NativeScript app using the MVVM pattern, where should business logic and data transformation typically reside?
- XML/HTML template files
- The ViewModel class (Correct answer)
- The native module layer
- The app.js bootstrap file
Correct answer: The ViewModel class
The ViewModel class handles business logic and data transformation, keeping the View (XML/HTML) and Model (raw data) decoupled.
Question 7: Which NativeScript module allows persistent local storage of application state across sessions?
- @nativescript/core/application-settings (Correct answer)
- ApplicationStore
- PersistentObservable
- SessionCache
Correct answer: @nativescript/core/application-settings
The ApplicationSettings module (part of @nativescript/core) provides key-value storage backed by NSUserDefaults (iOS) and SharedPreferences (Android) for persistent state.
Which NativeScript class is the base class for all observable objects used in state management?