• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript store.Store类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中@ngxs/store.Store的典型用法代码示例。如果您正苦于以下问题:TypeScript Store类的具体用法?TypeScript Store怎么用?TypeScript Store使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Store类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: describe

describe('Filter', () => {
  let store: Store;

  beforeEach(async(() => {
    TestBed.configureTestingModule({ imports: [NgxsModule.forRoot([FilterState])] }).compileComponents();
    store = TestBed.get(Store);
  }));

  it('it should set location', () => {
    store.dispatch(new SetLocation({ latitude: 10, longitude: 10 }));
    store.selectOnce(state => state.filter.location).subscribe(location => {
      expect(location.latitude).toBe(10);
      expect(location.longitude).toBe(10);
    });
  });

  it('it should set distance', () => {
    store.dispatch(new SetDistance(100));
    store.selectOnce(state => state.filter.distance).subscribe(distance => {
      expect(distance).toBe(100);
    });
  });

  it('it should set rating', () => {
    store.dispatch(new SetRating(5));
    store.selectOnce(state => state.filter.rating).subscribe(rating => {
      expect(rating).toBe(5);
    });
  });

  it('it should set reviews', () => {
    store.dispatch(new SetReviews(50));
    store.selectOnce(state => state.filter.reviews).subscribe(reviews => {
      expect(reviews).toBe(50);
    });
  });
});
开发者ID:estrellajm,项目名称:itinerary,代码行数:37,代码来源:filter.state.spec.ts


示例2: describe

describe('panelComponent', () => {
  let component: PanelComponent;
  let fixture: ComponentFixture<PanelComponent>;
  const FakeAuthService = {
    authState: of({ uid: 1 })
  } as any;

  const fakeToolsService = jasmine.createSpyObj('ToolsService', [
    'init',
    'joinRoom',
    'sendCommand'
  ]);
  const fakeCaptionService = jasmine.createSpyObj('fakeCaptionService', [
    'initFireStore',
    'getCaptionList',
    'getAreaPosition',
    'getCustomCSS'
  ]);
  let store: Store;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [PanelComponent],
      imports: [
        HttpClientTestingModule,
        NgxsModule.forRoot([EnvironmentState, CaptionItemsState])
      ],
      providers: [
        { provide: AuthService, useValue: FakeAuthService },
        { provide: ToolsService, useValue: fakeToolsService },
        { provide: CaptionService, useValue: fakeCaptionService }
      ]
    }).compileComponents();
    store = TestBed.get(Store);
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(PanelComponent);
    component = fixture.componentInstance;
    fakeCaptionService.getCaptionList.and.returnValue(of([]));
    fakeCaptionService.getAreaPosition.and.returnValue(of([]));
    fakeCaptionService.getCustomCSS.and.returnValue(of([]));
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  it('should send a message', () => {
    spyOn(component, 'buildCommand').and.returnValue({});
    component.sendMessage('', '');
    expect(fakeToolsService.sendCommand).toHaveBeenCalled();
  });

  it('should build a command model', () => {
    component.areaPosition = {
      startX: 0,
      startY: 0,
      maxHeight: 0,
      maxWidth: 0
    };
    spyOn(component, 'getRandomNumber').and.callFake(
      (startNumber, maxNumber) => startNumber
    );
    const inputValue = 'test';
    const outputValue = {
      command: 'message',
      message: inputValue,
      className: `fz1 `,
      style: {
        left: `0px`,
        top: `0px`,
        transform: `rotate(-45deg)`
      }
    };
    expect(component.buildCommand(inputValue, '')).toEqual(outputValue);
  });

  it('should return number', () => {
    spyOn(Math, 'random').and.returnValue(0.5);
    expect(component.getRandomNumber(1, 10)).toBe(6);
  });

  it('should dispatch AddCaption', () => {
    const item = {};
    spyOn(store, 'dispatch');
    component.addCaption(item);
    expect(store.dispatch).toHaveBeenCalledWith(new AddCaption(item));
  });

  it('should dispatch saveCaption', () => {
    const item = {};
    spyOn(store, 'dispatch');
    component.saveCaption(item);
    expect(store.dispatch).toHaveBeenCalledWith(new UpdateCaption(item));
  });

  it('should dispatch removeCaption', () => {
    const item = { id: 1 };
//.........这里部分代码省略.........
开发者ID:chgc,项目名称:stream-tools,代码行数:101,代码来源:panel.component.spec.ts


示例3: ngxsOnInit

  ngxsOnInit({ dispatch }: StateContext<SiteSettingsConfigStateModel>) {
    concat(
      this.appStateService.getInitialState('', 'siteSettingsConfig').pipe(take(1)),
      this.actions$.pipe(ofActionSuccessful(UserLoginAction), switchMap(() => {
        return this.appStateService.getInitialState('', 'siteSettingsConfig').pipe(take(1));
      }))
    )
    .subscribe({
      next: (siteSettingsConfig: SiteSettingsConfigResponse) => {
        dispatch(new InitSiteSettingsConfigAction(siteSettingsConfig));
      },
      error: (error) => console.error(error)
    });

    // Listen for language change
    this.store.select(SiteSettingsState.getCurrentSiteLanguage).pipe(
      pairwise(),
      filter(([prevLang, lang]) => !!prevLang && !!lang && prevLang !== lang),
      switchMap(([, language]) => this.appStateService.getLocaleSettings(language, 'siteSettingsConfig').pipe(take(1)))
    ).subscribe((siteSettingsConfig: SiteSettingsConfigResponse) => {
      dispatch(new InitSiteSettingsConfigAction(siteSettingsConfig));
    });
  }
开发者ID:berta-cms,项目名称:berta,代码行数:23,代码来源:site-settings-config.state.ts


示例4: ngOnInit

  ngOnInit() {
    this.productGroups$ = combineLatest(
      this.store.select(SiteSectionsState.getCurrentSiteShopSections),
      this.store.select(SectionTagsState.getCurrentSiteTags),
      this.store.select(SectionEntriesState.getCurrentSiteEntries),
      this.store.select(ShopProductsState.getCurrentSiteProducts)
    ).pipe(
      map(([sections, tags, entries, products]: [SiteSectionStateModel[], SectionTagsInterface[], SectionEntry[], any]) => {
        let leftOverProducts = [...products];

        // 1. Add entry data to products
        let productData: any[] = entries.reduce((_productData, entry) => {

          leftOverProducts = leftOverProducts.reduce((_prodRef, product, idx) => {
            const attributes = entry.content && entry.content.cartAttributes ? entry.content.cartAttributes.split(/,\s*/i) : [];
            const name = entry.content && entry.content.cartTitle || '';

            if (product.uniqid === entry.uniqid) {

              if ((attributes.length === 0 && product.name === name) ||
                  attributes.map(attribute => name + (name.length ? ' ' : '') + attribute).indexOf(product.name) > -1) {
                _productData.push({
                  ...product,
                  entry: entry  // make this more precise, we don't need all the properties of entry here
                });
              } else {
                // Ignore any products with this ID and not matching attributes, because they're "deleted"
              }

            } else {
              _prodRef.push(product);
            }

            return _prodRef;
          }, []);

          return _productData;
        }, []);

        // 2. Group products according to entry location in Sections and Tags
        const groups = sections.reduce((_groups, section) => {
          let sectionProducts, sectionTagProducts;

          [sectionProducts, sectionTagProducts, productData] = productData
            .reduce(([_groupProducts, _sectionTagProducts, leftOverProductData], product) => {
              if (product.entry.sectionName === section.name) {

                if ((!product.entry.tags || product.entry.tags.tag.length === 0)) {
                  _groupProducts.push(product);
                } else {
                  _sectionTagProducts.push(product);
                }

              } else {
                leftOverProductData.push(product);
              }

              return [_groupProducts, _sectionTagProducts, leftOverProductData];
            }, [[], [], []]);

          // Add section as entry group
          const sectionTags = tags.find(tag => tag['@attributes'].name === section.name && tag.tag.length > 0);
          _groups.push({
            isTag: false,
            name: section.name,
            title: section.title,
            products: sectionProducts,
            hasProducts: sectionTags && sectionTagProducts.length > 0
          });

          if (sectionTags) {
            const tagGroups = [...sectionTags.tag]
              .sort((tagA, tagB) => tagA.order - tagB.order)
              .map(tag => {
                const tagProducts = sectionTagProducts.filter((product) => {
                  return product.entry.tags.tag.some(entryTag => entryTag === tag['@value']);
                });

                return {
                  isTag: true,
                  name: tag['@attributes'].name,
                  title: tag['@value'],
                  products: tagProducts,
                  hasProducts: tagProducts.length > 0
                };
              });

              return [..._groups, ...tagGroups];
          }

          return _groups;
        }, []);

        // if (leftOverProducts.length > 0 && isDevMode()) {
        //   groups.push({
        //     title: 'No section',
        //     products: leftOverProducts
        //   });
        // }

//.........这里部分代码省略.........
开发者ID:berta-cms,项目名称:berta,代码行数:101,代码来源:shop-products.component.ts


示例5: updateProducts

 updateProducts(field: string, value, id: string) {
   this.store.dispatch(new UpdateShopProductAction(id, {field, value}));
 }
开发者ID:berta-cms,项目名称:berta,代码行数:3,代码来源:shop-products.component.ts


示例6: unauthorized

 @Action(UnauthorizedAccessAction)
 unauthorized(ctx: StateContext<SessionStateModel>, {payload}: UnauthorizedAccessAction) {
     this.store.dispatch([new OpenLoginDialogAction(payload)]);
 }
开发者ID:strongbox,项目名称:strongbox-web-ui,代码行数:4,代码来源:session.state.ts


示例7: ngxsOnInit

 ngxsOnInit(ctx: StateContext<SessionStateModel>) {
     this.store.dispatch(new CheckCredentialsAction());
 }
开发者ID:strongbox,项目名称:strongbox-web-ui,代码行数:3,代码来源:session.state.ts


示例8: openSidenav

 openSidenav() {
   this.store.dispatch(new layout.OpenSidenav());
 }
开发者ID:estrellajm,项目名称:itinerary,代码行数:3,代码来源:app.component.ts


示例9: updateComponentFocus

 updateComponentFocus(isFocused) {
   this.store.dispatch(new UpdateInputFocus(isFocused));
 }
开发者ID:berta-cms,项目名称:berta,代码行数:3,代码来源:site-sections.component.ts


示例10: ngOnInit

 public ngOnInit() {
   this.store.dispatch(new CounterStateChangeAction());
 }
开发者ID:LucasFrecia,项目名称:store,代码行数:3,代码来源:counter.component.ts



注:本文中的@ngxs/store.Store类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript arkhamjs.Flux类代码示例发布时间:2022-05-28
下一篇:
TypeScript store.StateContext类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap