How to use @datorama/akita - 10 common examples

To help you get started, we’ve selected a few @datorama/akita 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 dockstore / dockstore-ui2 / src / app / organizations / state / collections.service.ts View on Github external
},
        () => {
          this.collectionsStore.setError(true);
        }
      );
  }

  /**
   * Currently only used from the collection page
   * Grabs detailed collection information and navigates to the collection's page
   *
   * @param {number} organizationId  The ID of the organization that the collection belongs to
   * @param {number} collectionId  The ID of the collection
   * @memberof CollectionsService
   */
  @transaction()
  updateCollectionFromId(organizationId: number, collectionId: number) {
    this.collectionsStore.setError(false);
    this.collectionsStore.setLoading(true);
    this.organizationsService
      .getCollectionById(organizationId, collectionId)
      .pipe(finalize(() => this.collectionsStore.setLoading(false)))
      .subscribe(
        (collection: Collection) => {
          this.collectionsStore.setError(false);
          this.collectionsStore.upsert(collection.id, collection);
          this.collectionsStore.setActive(collection.id);
          this.organizationService.updateOrganizationFromID(collection.organizationID);
          // Navigate to the new collectionName in case the name changes.
          this.router.navigate(['/organizations', collection.organizationName, 'collections', collection.name]);
        },
        () => {
github dockstore / dockstore-ui2 / src / app / shared / state / workflow.service.ts View on Github external
import { BioWorkflow } from '../swagger/model/bioWorkflow';
import { Service } from '../swagger/model/service';
import { ExtendedWorkflowService } from './extended-workflow.service';
import { WorkflowStore } from './workflow.store';

@Injectable({ providedIn: 'root' })
export class WorkflowService {
  workflows$: BehaviorSubject = new BehaviorSubject(null); // This contains the list of unsorted workflows
  sharedWorkflows$: BehaviorSubject = new BehaviorSubject(null); // This contains the list of unsorted shared workflows
  nsSharedWorkflows$: BehaviorSubject = new BehaviorSubject(null); // This contains the list of sorted shared workflows
  nsWorkflows$: BehaviorSubject = new BehaviorSubject(null); // This contains the list of sorted workflows
  private copyBtnSource = new BehaviorSubject(null); // This is the currently selected copy button.
  copyBtn$ = this.copyBtnSource.asObservable();
  constructor(private workflowStore: WorkflowStore, private extendedWorkflowService: ExtendedWorkflowService) {}

  @transaction()
  setWorkflow(workflow: BioWorkflow | Service | null) {
    if (workflow) {
      this.workflowStore.upsert(workflow.id, workflow);
      this.extendedWorkflowService.update(workflow);
      this.workflowStore.setActive(workflow.id);
    } else {
      this.workflowStore.remove();
      this.extendedWorkflowService.remove();
    }
  }

  get() {
    // Placeholder
    // this.http.get('https://akita.com').subscribe((entities) => this.workflowStore.set(entities));
  }
github datorama / akita / angular / playground / src / app / widgets / widgets.component.ts View on Github external
ngOnInit() {
    if (this.widgetsQuery.hasEntity() === false) {
      this.widgetService.initWidgets();
    }
    this.dashoboardName$ = this.widgetsQuery.select(state => state.name);
    this.widgets$ = this.widgetsQuery.selectAll();
    this.activeWidgets$ = this.widgetsQuery.selectActive();
    this.collection = new DirtyCheckPlugin(this.widgetsQuery, {
      watchProperty: 'entities'
    }).setHead();
    this.widgetsSpecific = new EntityDirtyCheckPlugin(
      this.widgetsQuery
    ).setHead();
  }
github datorama / akita / angular / playground / src / app / widgets / widgets.component.ts View on Github external
ngOnInit() {
    if (this.widgetsQuery.hasEntity() === false) {
      this.widgetService.initWidgets();
    }
    this.dashoboardName$ = this.widgetsQuery.select(state => state.name);
    this.widgets$ = this.widgetsQuery.selectAll();
    this.activeWidgets$ = this.widgetsQuery.selectActive();
    this.collection = new DirtyCheckPlugin(this.widgetsQuery, {
      watchProperty: 'entities'
    }).setHead();
    this.widgetsSpecific = new EntityDirtyCheckPlugin(
      this.widgetsQuery
    ).setHead();
  }
github datorama / akita / angular / playground / src / app / todos-app / todos-page / todos-page.component.ts View on Github external
ngOnInit() {
    this.todos$ = this.todosQuery.selectVisibleTodos$;
    this.activeFilter$ = this.todosQuery.selectVisibilityFilter$;
    this.checkAll$ = this.todosQuery.checkAll$.pipe(map(numCompleted => numCompleted && numCompleted === this.todosQuery.getCount()));
    this.stateHistory = new StateHistoryPlugin(this.todosQuery);
    this.stateHistoryEntity = new EntityStateHistoryPlugin(this.todosQuery);
  }
github datorama / akita / angular / playground / src / app / todos-app / todos-page / todos-page.component.ts View on Github external
ngOnInit() {
    this.todos$ = this.todosQuery.selectVisibleTodos$;
    this.activeFilter$ = this.todosQuery.selectVisibilityFilter$;
    this.checkAll$ = this.todosQuery.checkAll$.pipe(map(numCompleted => numCompleted && numCompleted === this.todosQuery.getCount()));
    this.stateHistory = new StateHistoryPlugin(this.todosQuery);
    this.stateHistoryEntity = new EntityStateHistoryPlugin(this.todosQuery);
  }
github datorama / akita / angular / playground / src / app / widgets / state / widgets.store.ts View on Github external
import { Injectable } from '@angular/core';
import { Widget } from './widget.model';
import { EntityState, EntityStore, StoreConfig, MultiActiveState } from '@datorama/akita';

export interface WidgetsState extends EntityState, MultiActiveState {
  name: string;
}

const initState = {
  name: 'Akita widgets',
  active: []
};

@Injectable({ providedIn: 'root' })
@StoreConfig({ name: 'widgets' })
export class WidgetsStore extends EntityStore {
  constructor() {
    super(initState);
  }
}
github datorama / akita / examples / akita-angular-server-side-pagination / src / app / contacts / state / contacts.store.ts View on Github external
import { Injectable } from '@angular/core';
import { EntityState, EntityStore, StoreConfig } from '@datorama/akita';
import { Contact } from './contact.model';

export interface ContactsState extends EntityState {}

@Injectable({ providedIn: 'root' })
@StoreConfig({ name: 'contacts' })
export class ContactsStore extends EntityStore {
  constructor() {
    super();
  }
}
github datorama / akita / angular / playground / src / app / contacts / state / contacts.store.ts View on Github external
import { Injectable } from '@angular/core';
import { Contact } from './contact.model';
import { EntityState, EntityStore, StoreConfig } from '@datorama/akita';

export interface ContactState extends EntityState {}

@Injectable({ providedIn: 'root' })
@StoreConfig({ name: 'contacts' })
export class ContactsStore extends EntityStore {
  constructor() {
    super();
  }
}
github dockstore / dockstore-ui2 / src / app / entry / entry-file-tab / state / entry-file-tab.store.ts View on Github external
export function createInitialState(): EntryFileTabState {
  return {
    unfilteredFiles: null,
    fileTypes: null,
    selectedFileType: null,
    files: null,
    selectedFile: null,
    fileContents: null,
    downloadFilePath: null,
    validationMessage: null
  };
}

@Injectable()
@StoreConfig({ name: 'entry-file-tab' })
export class EntryFileTabStore extends Store {
  constructor() {
    super(createInitialState());
  }
}