How to use the knockout.computed function in knockout

To help you get started, we’ve selected a few knockout 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 FredrikNoren / ungit / components / graph / selectable.js View on Github external
constructor(graph) {
    this.selected = ko.computed({
      read() {
        return graph.currentActionContext() == this;
      },
      write(val) {
        // val is this if we're called from a click ko binding
        if (val === this || val === true) {
          graph.currentActionContext(this);
        } else if (graph.currentActionContext() == this) {
          graph.currentActionContext(null);
        }
      },
      owner: this
    });
  }
}
github FredrikNoren / ungit / components / graph / git-graph-actions.js View on Github external
constructor(graph, node) {
    super(graph, 'Move', 'move', 'glyph_icon glyph_icon-move');
    this.node = node;
    this.visible = ko.computed(() => {
      if (this.isRunning()) return true;
      return this.graph.currentActionContext() instanceof RefViewModel &&
        this.graph.currentActionContext().node() != this.node;
    });
  }
  perform() {
github FredrikNoren / ungit / components / stash / stash.js View on Github external
constructor(server, repoPath) {
    this.server = server;
    this.repoPath = repoPath;
    this.stashedChanges = ko.observable([]);
    this.isShow = ko.observable(storage.getItem('showStash') === 'true');
    this.visible = ko.computed(() => this.stashedChanges().length > 0 && this.isShow());
    this.refresh();
  }
github FredrikNoren / ungit / components / textdiff / textdiff.js View on Github external
constructor() {
    this.text = ko.observable("No Wrap");
    this.value = ko.observable(false);
    this.value.subscribe(value => { this.text(value ? "Word Wrap" : "No Wrap"); });
    this.toggle = () => { this.value(!this.value()); }
    this.isActive = ko.computed(() => !!this.value());
  }
}
github Azure / api-management-developer-portal / src / components / users / user-details / ko / runtime / user-details.ts View on Github external
constructor(
        private readonly usersService: UsersService, 
        private readonly tenantService: TenantService,
        private readonly backendService: BackendService,
        private readonly router: Router) {
        this.user = ko.observable();
        this.firstName = ko.observable();
        this.lastName = ko.observable();
        this.email = ko.observable();
        this.password = ko.observable();
        this.confirmPassword = ko.observable();
        this.isEdit = ko.observable(false);
        this.isBasicAccount = ko.observable(false);
        this.working = ko.observable(false);
        this.registrationDate = ko.computed(() => this.getRegistrationDate());
    }

knockout

Knockout makes it easier to create rich, responsive UIs with JavaScript

MIT
Latest version published 5 years ago

Package Health Score

62 / 100
Full package analysis