nextcloud-files icon indicating copy to clipboard operation
nextcloud-files copied to clipboard

fix: Make `View` methods bound to `ViewData` object

Open susnux opened this issue 1 year ago • 1 comments

Use case: You want to scope logic and state into the view rather than somewhere in a module.

Problem: The View class wraps the ViewData as a getter, meaning instead of calling the function on the object, it just returns the reference to the function within the object. This means the function looses the reference to the object as this.


  • This is an alternative for https://github.com/nextcloud-libraries/nextcloud-files/pull/1067

Instead of making View a real class that can be extended, this just allows to use stateful ViewData. Meaning function like getContents and loadChildView do not loose the this context, but can still work with it. This is useful to have stateful views, e.g. the favorites view which needs to load children based on a state (nodes added / removed).

susnux avatar Sep 03 '24 22:09 susnux

Bundle Report

Changes will increase total bundle size by 106 bytes :arrow_up:

Bundle name Size Change
@nextcloud/files-esm 117.42kB 53 bytes :arrow_up:
@nextcloud/files-esm-cjs 118.8kB 53 bytes :arrow_up:

codecov[bot] avatar Sep 03 '24 22:09 codecov[bot]