Search code examples
angulartypescriptngrx

How to save files in ngrx store?


Since last week I have migrated my app to ngrx. Now I'm facing a problem: My app needs access to File objects the whole time my app runs. Because ngrx stores JSON objects only, it can't store File objects and other type of classes.

What is the best way to handle File objects using ngrx? Do I have to convert them to JSON objects and save them to the store or do I have to save them out of the store? Or is there any other way?

Context: the app does audio processing and makes use of other text files.

For further processing I need the contents of the file, its name and size. I thought about making a JSON object, but this could be inefficient (because ngrx creates copies of its state):

{
  name: string;
  size: number;
  buffer: ArrayBuffer;
}

Solution

  • ngrx can store File objects just like any other service. Because the redux plugin for the browser can't output the File object correctly I thought File objects are not supported by ngrx. If I output the current state to the console the list of files is available as it should be.