How to use the @datorama/akita.transaction function in @datorama/akita

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 dockstore / dockstore-ui2 / src / app / shared / state / token.service.ts View on Github external
import { Observable, throwError } from 'rxjs';
import { Provider } from '../enum/provider.enum';
import { TokensService, UsersService } from '../swagger';
import { Token } from '../swagger/model/token';
import { TokenStore } from './token.store';

@Injectable({ providedIn: 'root' })
export class TokenService {
  constructor(
    private tokenStore: TokenStore,
    private tokensService: TokensService,
    private usersService: UsersService,
    private httpBackend: HttpBackend
  ) {}

  @transaction()
  get(userId: number) {
    this.tokenStore.remove();
    if (userId) {
      this.usersService.getUserTokens(userId).subscribe((tokens: Array) => {
        this.tokenStore.add(tokens);
      });
    }
  }

  add(token: Token) {
    this.tokenStore.add(token);
  }

  update(id, token: Partial) {
    this.tokenStore.update(id, token);
  }
github dockstore / dockstore-ui2 / src / app / aliases / state / aliases.service.ts View on Github external
) {}

  clearState(): void {
    this.aliasesStore.update(state => {
      return {
        ...state,
        organization: null,
        collection: null,
        tool: null,
        workflow: null,
        workflowVersion: null
      };
    });
  }

  @transaction()
  updateOrganizationFromAlias(alias: string): void {
    this.clearState();
    this.aliasesStore.setLoading(true);
    this.organizationsService
      .getOrganizationByAlias(alias)
      .pipe(finalize(() => this.aliasesStore.setLoading(false)))
      .subscribe(
        (organization: Organization) => {
          this.aliasesStore.setError(false);
          this.updateOrganization(organization);
        },
        () => {
          this.aliasesStore.setError(true);
        }
      );
  }
github dockstore / dockstore-ui2 / src / app / shared / tool / tool.service.ts View on Github external
setTool(tool: DockstoreTool | null) {
    if (tool) {
      this.toolStore.upsert(tool.id, tool);
      this.extendedDockstoreToolService.update(tool);
      this.toolStore.setActive(tool.id);
    } else {
      this.toolStore.remove();
      this.extendedDockstoreToolService.remove();
    }
  }

  clearActive() {
    this.toolStore.setActive(null);
  }

  @transaction()
  setTags(workflowVersions: Array | null) {
    this.toolStore.updateActive(active => {
      return {
        ...active.workflowVersions,
        workflowVersions
      };
    });
    this.extendedDockstoreToolService.update(this.toolQuery.getActive());
  }
}
github datorama / akita / angular / playground / src / app / movies / state / movies.service.ts View on Github external
this.moviesStore.set(movies);
      })
    );

    return this.moviesQuery.getHasCache() ? of() : request$;
  }

  updateActorName(id: ID, name: string) {
    this.actorsStore.update(id, { name });
  }

  markAsOpen(id: ID) {
    this.moviesStore.ui.update(id, entity => ({ isOpen: !entity.isOpen }));
  }

  @transaction()
  deleteActor(id: ID) {
    this.actorsStore.remove(id);
    this.moviesStore.update(null, entity => ({ actors: arrayRemove(entity.actors, id) }));
  }
}
github dockstore / dockstore-ui2 / src / app / aliases / state / aliases.service.ts View on Github external
() => {
          this.aliasesStore.setError(true);
        }
      );
  }

  updateTool(tool: DockstoreTool) {
    this.aliasesStore.update(state => {
      return {
        ...state,
        tool: tool
      };
    });
  }

  @transaction()
  updateWorkflowFromAlias(alias: string): void {
    this.clearState();
    this.aliasesStore.setLoading(true);
    this.workflowsService
      .getWorkflowByAlias(alias)
      .pipe(finalize(() => this.aliasesStore.setLoading(false)))
      .subscribe(
        (workflow: Workflow) => {
          this.aliasesStore.setError(false);
          this.updateWorkflow(workflow);
        },
        () => {
          this.aliasesStore.setError(true);
        }
      );
  }
github dockstore / dockstore-ui2 / src / app / entry / state / current-collections.service.ts View on Github external
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { ID, transaction } from '@datorama/akita';
import { CollectionOrganization, EntriesService } from '../../shared/swagger';
import { CurrentCollectionsStore } from './current-collections.store';

@Injectable({ providedIn: 'root' })
export class CurrentCollectionsService {
  constructor(private currentCollectionsStore: CurrentCollectionsStore, private entriesService: EntriesService, private http: HttpClient) {}

  @transaction()
  get(id: number) {
    if (id) {
      this.entriesService.entryCollections(id).subscribe((CollectionOrganizations: Array) => {
        this.currentCollectionsStore.remove();
        this.currentCollectionsStore.set(CollectionOrganizations);
      });
    } else {
      this.currentCollectionsStore.remove();
    }
  }

  add(currentCollection: CollectionOrganization) {
    this.currentCollectionsStore.add(currentCollection);
  }

  update(id, currentCollection: Partial) {
github dockstore / dockstore-ui2 / src / app / shared / user / user.service.ts View on Github external
...state,
        user: user
      };
    });
  }

  updateExtendedUserData(extendeduserData: ExtendedUserData) {
    this.userStore.update(state => {
      return {
        ...state,
        extendedUserData: extendeduserData
      };
    });
  }

  @transaction()
  remove() {
    this.userStore.update({ user: null, extendedUserData: null });
    this.tokenService.removeAll();
  }

  setupConfigurationToken(): void {
    const token = this.authService.getToken();
    this.configuration.apiKeys['Authorization'] = token ? 'Bearer ' + token : null;
  }

  getExtendedUserData(): void {
    this.setupConfigurationToken();
    if (this.configuration.apiKeys['Authorization']) {
      this.usersService
        .getExtendedUserData()
        .subscribe(
github dockstore / dockstore-ui2 / src / app / aliases / state / aliases.service.ts View on Github external
() => {
          this.aliasesStore.setError(true);
        }
      );
  }

  updateOrganization(organization: Organization) {
    this.aliasesStore.update(state => {
      return {
        ...state,
        organization: organization
      };
    });
  }

  @transaction()
  updateCollectionFromAlias(alias: string): void {
    this.clearState();
    this.aliasesStore.setLoading(true);
    this.organizationsService
      .getCollectionByAlias(alias)
      .pipe(finalize(() => this.aliasesStore.setLoading(false)))
      .subscribe(
        (collection: Collection) => {
          this.aliasesStore.setError(false);
          this.updateCollection(collection);
        },
        () => {
          this.aliasesStore.setError(true);
        }
      );
  }