How to use the @ngrx/store.Store function in @ngrx/store

To help you get started, we’ve selected a few @ngrx/store 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 ngrx-utils / ngrx-utils / projects / store / src / spec / decorators / select.spec.ts View on Github external
bar: {
        a: {
          b: {
            c: {
              d: 'world'
            }
          }
        }
      }
    }
  };

  const msFeature = createFeatureSelector('myFeature');
  const msBar = createSelector(msFeature, state => state.bar);

  const store = new Store(of(globalState), undefined as any, undefined as any);

  it('selects sub state with Select decorator', () => {
    NgrxSelect.store = store;
    class MyStateSelector {
      @Select(msBar) bar$: Observable; // using MemoizedSelector
    }

    const mss = new MyStateSelector();

    mss.bar$.subscribe(n => {
      expect(n).toBe(globalState.myFeature.bar);
    });
  });

  it('should apply pipeable operator when provided', () => {
    NgrxSelect.store = store;
github amcdnl / ngrx-actions / src / spec / index.spec.ts View on Github external
}
      }
    };

    const msFeature = createFeatureSelector('myFeature');
    const msBar = createSelector(msFeature, state => state.bar);

    class MyStateSelector {
      @Select('myFeature.bar.a.b.c.d') hello$: Observable; // deeply nested props
      @Select() myFeature: Observable; // implied by name
      @Select(msBar) bar$: Observable; // using MemoizedSelector
      @Select(state => [])
      bar2$: Observable; // Remapping to different obj
    }

    const store = new NgRxStore(of(globalState), undefined, undefined);

    try {
      NgrxSelect.store = store;

      const mss = new MyStateSelector();

      mss.hello$.subscribe(n => {
        expect(n).toBe('world');
      });

      mss.myFeature.subscribe(n => {
        expect(n).toBe(globalState.myFeature);
      });

      mss.bar2$.subscribe(n => {
        expect(n.length).toBe(0);
github DSpace / dspace-angular / src / app / core / cache / object-cache.service.spec.ts View on Github external
beforeEach(() => {
    init();
    store = new Store(undefined, undefined, undefined);
    spyOn(store, 'dispatch');
    service = new ObjectCacheService(store);

    spyOn(Date.prototype, 'getTime').and.callFake(() => {
      return timestamp;
    });
  });
github ngrx-utils / ngrx-utils / modules / store / spec / index.spec.ts View on Github external
bar: {
        a: {
          b: {
            c: {
              d: 'world'
            }
          }
        }
      }
    }
  };

  const msFeature = createFeatureSelector('myFeature');
  const msBar = createSelector(msFeature, state => state.bar);

  const store = new Store(of(globalState), undefined as any, undefined as any);

  afterEach(() => {
    NgrxSelect.store = undefined;
  });

  describe('modules', () => {
    it('should create module', () => {
      const ngrxSelect = new NgrxSelect();
      spyOn(ngrxSelect, 'connect').and.callThrough();
      expect(ngrxSelect).toBeTruthy();
      expect(new NgrxUtilsModule(ngrxSelect, store)).toBeTruthy();
      expect(ngrxSelect.connect).toHaveBeenCalled();
      expect(NgrxSelect.store).toEqual(store);
    });
  });
github ngrx-utils / ngrx-utils / projects / store / src / spec / decorators / ngrx-select-module.spec.ts View on Github external
describe('NgrxSelectModule', () => {
  const store = new Store(of({}), undefined as any, undefined as any);

  afterEach(() => {
    NgrxSelect.store = undefined;
  });

  describe('modules', () => {
    it('should create module', () => {
      const ngrxSelect = new NgrxSelect();
      spyOn(ngrxSelect, 'connect').and.callThrough();
      expect(ngrxSelect).toBeTruthy();
      const module = new NgrxSelectModule(ngrxSelect, store, undefined as any);
      expect(module).toBeTruthy();
      expect(ngrxSelect.connect).toHaveBeenCalled();
      expect(NgrxSelect.store).toEqual(store);
      expect(() => new NgrxSelectModule(ngrxSelect, store, {})).toThrowError();
    });
github ngrx-utils / ngrx-utils / projects / store / src / spec / decorators / dispatch.spec.ts View on Github external
describe('Dispatch', () => {
  const store = new Store(of({}), new ActionsSubject(), undefined as any);
  const action1 = { type: 'test-action1' };
  const action2 = { type: 'test-action2' };

  it('should dispatch action', () => {
    spyOn(store, 'dispatch').and.callThrough();
    NgrxSelect.store = store;
    class TestComponent {
      @Dispatch()
      onAction() {
        return action1;
      }
    }

    const testComp = new TestComponent();
    testComp.onAction();
    expect(store.dispatch).toHaveBeenCalledWith(action1);
github DSpace / dspace-angular / src / app / shared / host-window.service.spec.ts View on Github external
beforeEach(() => {
      const _initialState = { hostWindow: { width: 1100, height: 770 } };
      store = new Store(observableOf(_initialState), undefined, undefined);
      service = new HostWindowService(store);
    });
github DSpace / dspace-angular / src / app / core / cache / request-cache.service.spec.ts View on Github external
beforeEach(() => {
    store = new Store(undefined, undefined, undefined);
    spyOn(store, 'dispatch');
    service = new RequestCacheService(store);
    spyOn(window, 'Date').and.returnValue({ getTime: () => timestamp });
  });
github DSpace / dspace-angular / src / app / core / data / request.service.spec.ts View on Github external
beforeEach(() => {
    scheduler = getTestScheduler();

    objectCache = getMockObjectCacheService();
    (objectCache.hasBySelfLink as any).and.returnValue(false);

    uuidService = getMockUUIDService();

    store = new Store(new BehaviorSubject({}), new ActionsSubject(), null);
    selectSpy = spyOnProperty(ngrx, 'select');
    selectSpy.and.callFake(() => {
      return () => {
        return () => cold('a', { a: undefined });
      };
    });

    service = new RequestService(
      objectCache,
      uuidService,
      store,
      undefined
    );
    serviceAsAny = service as any;
  });
github DSpace / dspace-angular / src / app / core / metadata / metadata.service.spec.ts View on Github external
beforeEach(() => {

    store = new Store(undefined, undefined, undefined);
    spyOn(store, 'dispatch');

    objectCacheService = new ObjectCacheService(store);
    uuidService = new UUIDService();
    requestService = new RequestService(objectCacheService, uuidService, store, undefined);
    remoteDataBuildService = new RemoteDataBuildService(objectCacheService, requestService);

    TestBed.configureTestingModule({
      imports: [
        CommonModule,
        StoreModule.forRoot({}),
        TranslateModule.forRoot({
          loader: {
            provide: TranslateLoader,
            useClass: MockTranslateLoader
          }