Skip to content
This repository has been archived by the owner on Jan 10, 2018. It is now read-only.

Default state values not set for reducers when using object shorthand and in AOT compiled context #342

Closed
wesleycho opened this issue Feb 26, 2017 · 1 comment

Comments

@wesleycho
Copy link
Contributor

wesleycho commented Feb 26, 2017

When an app is compiled via AOT compilation, the default state values are not set at all, and one gets undefined when trying to fetch them from the store - this is a regression caused somewhere in between Angular 2.2 and 2.4. This may potentially be an Angular bug at its root, but I only came across it with this library so perhaps someone can do a deeper dive (unfortunately I don't get to do much coding anymore :( ).

Here is a snippet of the problematic code & the workaround

// breaks
    StoreModule.provideStore({
      course,
      courseHistory,
      slides,
      selectedFiles,
      selectedSlides,
      slideCollection,
      audioPlayer: audioPlayerReducer,
      times: timesReducer,
      mediaRecorder: mediaRecorderReducer,
      saveAudio: saveAudioReducer
    }, {
      course: {},
      courseHistory: {},
      slides: [],
      selectedFiles: [],
      selectedSlides: []
    })

// works
    StoreModule.provideStore({
      course: course,
      courseHistory: courseHistory,
      slides: slides,
      selectedFiles: selectedFiles,
      selectedSlides: selectedSlides,
      slideCollection: slideCollection,
      audioPlayer: audioPlayerReducer,
      times: timesReducer,
      mediaRecorder: mediaRecorderReducer,
      saveAudio: saveAudioReducer
    }, {
      course: {},
      courseHistory: {},
      slides: [],
      selectedFiles: [],
      selectedSlides: []
    })

It should be noted that I encountered this because I noticed that the store was returning undefined for the slides value being fetched like this.store.select(s => s.slides).subscribe(slides => ...), which caused catastrophic failure in the app.

Angular version: 2.4.7
@ngtools/webpack: 1.2.9
@ngrx/store: 2.2.1

@robwormald
Copy link
Contributor

Please check this against NgRx v4, and if it’s still an issue, please reopen on https://github.com/ngrx/platform. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants