ensure mounted directories are unique #98
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR filters the given
$paths, $uses
inMountedDirectories::mount()
to ensure there isn't already aMountedDirectory
with the exact same properties.This won't break anything since it doesn't change any functionality. The same views as before will still be mounted, we just won't add a duplicate
MountedDirectory
instance for them to the$paths
array if one already exists.closes #96
EDIT (more context):
One might expect that mounting the same directory more than once with volt wouldn't change anything, and it doesn't. However there is an unfortunate and unexpected side effect: each call will increase memory usage by adding a new
MountedDirectory
instance to the manager's footprint with the same properties as the previous one, and for no useful reason as far as I can tell.Of course it looks like the $paths property isn't even being used anyway: the local $paths variable created directly from the given
$path, $uses
is being used instead to create the views using only the given parameters and ignoring the existing properties. But that is a separate issue and this pr just aims to decrease unwanted/unneeded memory usage regardless of the variable or scope used for view creation.It may be also worth looking at whether the views should be created from the given
$paths, $uses
, or all of the paths in thepaths
property as proposed in #95.A few of us have been looking into how to use
livewire/volt
in a package and provide components to a laravel application. One of the ways we've found to do this is by callingVolt::mount()
from a package's service provider. In order to prevent overwriting paths already mounted by the application, we've found that we can merge in the existing paths.However in doing so I've noticed that whether existing paths are merged in or not, Volt stores all the paths from all the calls to
mount()
regardless of whether or not they are being used. This includes duplicates, which serve no discernible purpose.#94
#92
#87