action not being detected by ngrx store angular

29 Views Asked by At

I am trying to dispatch an action to my ngrx store. The problem is the action is not being detected by the store. I have tested the event listener by dispatching another action from it and this is detected by my effect leading me to believe that the issue is with the action rather than the store or the effect that is listening for it. Any help or advice would be greatly appreciated.

Edit: I'm using the chrome API to add listeners when a tab is created or updated. These were both picking up changes to the existing tabs and firing off different actions. Was a concurrency issue, once I filtered when which listener could dispatch an action the action I was having an issue with was picked up by the store

appmodule:

@NgModule({
  declarations: [
    AppComponent,
    HomeComponent,
    GroupHomeComponent,
    LoginComponent,
    SessionInfoPopupComponent,
    AccountComponent,
    SessionSyncComponent,
    SessionComponent,
    ConfirmDeleteSessionComponent,
    CreateTabComponent
  ],
    imports: [
        BrowserModule,
        RoutingModule,
        BrowserAnimationsModule,
        MatTabsModule,
        MatInputModule,
        MatFormFieldModule,
        FormsModule,
        ReactiveFormsModule,
        MatCardModule,
        MatListModule,
        MatIconModule,
        MatCheckboxModule,
        StoreModule.forRoot(reducerMap),
        EffectsModule.forRoot([TabEffects, SessionEffects]),
        MatSelectModule,
        MatExpansionModule,
        DashboardModule,
        MatButtonModule,
        MatGridListModule,
        HttpClientModule,
        DashboardModule,
        MatTooltipModule,
        MatProgressSpinnerModule,
        MatDialogModule,
        MatSnackBarModule,
        MatRadioModule,
        MatCheckboxModule,
        MatSidenavModule,
        MatAutocompleteModule
    ],
  providers: [
    TabService,
    DashboardHomeService,
    SignInAuthGuard,
    LoginService,
    SessionInfoGroupResolver,
    NotificationService,
    SessionEffects,
    TabEffects,
    SessionService
  ]
  ,
  bootstrap: [AppComponent],
  exports: []
})
export class AppModule {
}

effect

  windowUpdateTab$ = createEffect(
    () => this.actions.pipe(
      ofType(SessionActions.SESSION_UPDATE_TAB_ACTION),
      tap(a => {console.log(a,"received")}),
      switchMap((action: UpdateTabAction) => {
        return this.store.select("session").pipe(
          switchMap(s => {
            const dbTabId = s.activeTabs.get(action.tab.id!)
            action.tab.id = dbTabId;
            return this.http.put(BACKEND_URL + "update/tab", action.tab, {withCredentials: true}).pipe(
              map(response => new UpdateTabSuccessAction(action.tab))
            )
          })
        )
      })
    )
  )

actions.ts

export class SessionUpdateTabAction implements Action {
  readonly type = SessionActions.SESSION_UPDATE_TAB_ACTION;
  constructor(public tab:Tab) {
  }
}````

event listener

export const onTabUpdate = (tab: Tab, store: Store<AppState>) => { store.pipe(select("session")).subscribe(s => { console.log(s.activeTabs.get(tab.id!)) 
store.dispatch(new UpdateTabAction(tab)) }) }

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {

  isLoading: boolean = true;

  constructor(private http: HttpClient, private store: Store<AppState>, private ref: ChangeDetectorRef) {
  }

  ngOnInit(): void {
    chrome.windows.onCreated.addListener((window) => onWindowCreated(window, this.store))
    chrome.windows.onRemoved.addListener((windowId: number) => onWindowClosed(windowId, this.store))
    chrome.tabs.onRemoved.addListener((tabId, tabRemoveInfo,) => onTabDeleted(tabId, this.store, tabRemoveInfo.windowId!))
    chrome.tabs.onCreated.addListener((tab) => onTabCreated(tab, this.store))
    chrome.tabs.onUpdated.addListener((tabId,changeInfo,tab) => onTabUpdate(tab,this.store))
  }

}

Hi, I am trying to dispatch an action to my ngrx store. The problem is the action is not being detected by the store nor the effects which are listening for actions of said type. I have tested the event listener by dispatching another action from it which is detected by my effect leading me to believe that the issue is with the action rather than the store or the effect that is listening for it. Any help or advice would be greatly appreciated.

0

There are 0 best solutions below