How to use the @nativescript/core/data/observable.Observable function in @nativescript/core

To help you get started, we’ve selected a few @nativescript/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NativeScript / NativeScript / tests / app / pages / tab-view.ts View on Github external
import { Observable } from "@nativescript/core/data/observable";

var vm = new Observable();

export function onPageLoaded(args) {
    var page = args.object;
    vm.set("firstTitle", "fiiiirst");
    vm.set("secondTitle", "secondTitle");
    vm.set("secondIcon", "res://icon");
    page.bindingContext = vm;
}
var i = 0;

export function onTap() {
    i++;
    vm.set("firstTitle", "changed " + i);
    if (i === 3) {
        vm.set("firstIcon", "res://ic_action");
    }
github NativeScript / NativeScript / unit-tests / observable / observable.ts View on Github external
beforeEach("create handlers", () => {
            handler = function() {
                callCount++;
            }
            observable = new Observable();
            observable.once("test", handler);
        });
        afterEach("reset handlers", () => {
github Notalib / nativescript-accessibility-ext / src / utils / utils.android.ts View on Github external
function ensureStateListener() {
  if (accessibilityStateChangeListener) {
    return sharedA11YObservable;
  }

  const a11yManager = getA11YManager();
  sharedA11YObservable = new Observable() as SharedA11YObservable;
  Object.defineProperty(sharedA11YObservable, AccessibilityServiceEnabledPropName, {
    get(this: SharedA11YObservable) {
      return this[A11yStateEnabledPropName] && this[TouchExplorationStateEnabledPropName];
    },
  });

  if (!a11yManager) {
    sharedA11YObservable.set(A11yStateEnabledPropName, false);
    sharedA11YObservable.set(TouchExplorationStateEnabledPropName, false);

    return sharedA11YObservable;
  }

  accessibilityStateChangeListener = new AccessibilityStateChangeListener({
    onAccessibilityStateChanged(enabled) {
      sharedA11YObservable.set(A11yStateEnabledPropName, !!enabled);
github Notalib / nativescript-accessibility-ext / src / utils / utils.ios.ts View on Github external
function ensureStateListener() {
  if (sharedA11YObservable) {
    return sharedA11YObservable;
  }

  sharedA11YObservable = new Observable() as SharedA11YObservable;

  sharedA11YObservable.set(AccessibilityServiceEnabledPropName, isAccessibilityServiceEnabled());

  if (typeof UIAccessibilityVoiceOverStatusDidChangeNotification !== 'undefined') {
    nativeObserver = nsApp.ios.addNotificationObserver(UIAccessibilityVoiceOverStatusDidChangeNotification, () =>
      sharedA11YObservable.set(AccessibilityServiceEnabledPropName, isAccessibilityServiceEnabled()),
    );

    nsApp.on(nsApp.exitEvent, () => {
      if (nativeObserver) {
        nsApp.ios.removeNotificationObserver(nativeObserver, UIAccessibilityVoiceOverStatusDidChangeNotification);
      }

      nativeObserver = null;
      sharedA11YObservable = null;
    });
github Notalib / nativescript-accessibility-ext / src / utils / FontScaleObservable.android.ts View on Github external
function ensureObservable() {
  if (internalObservable) {
    return;
  }

  internalObservable = new Observable();
  setupConfigListener();
}
github Notalib / nativescript-accessibility-ext / src / utils / FontScaleObservable.ios.ts View on Github external
function ensureObservable() {
  if (internalObservable) {
    return;
  }

  internalObservable = new Observable();
  setupConfigListener();
}