Method: collect.scope()
collect.scope(
scope
):ScopedMutate
Create scoped collect
, mutate
, and $mu
functions to avoid Collector name collisions.
Parameters
Parameter | Type | Description |
---|---|---|
scope | string | The scope name to prevent collector name collisions. |
Returns
ScopedMutate
An object containing scoped collect
, mutate
, and $mu
functions for the specified scope.
Examples
Scope the project to project-1
.
<button class="button">Click here</button>
const scoped = collect.scope('project-1');
const { collect, mutate } = scoped;
// Creates a collector with a scoped name `project-1:button`
collect('.button', 'button');
// Mutates scoped collector
mutate('button').text('Click now');
The button now has a scoped class name and the text has been changed. Any other
concurrent projects that collect under the name button
won't interfere with this one.
<button class="button mutate-project-1-button">Click now</button>
Scope using $mu()
collect.scope()
also works with $mu(), which combines collect
and mutate
into a single function;
<a class="next" href="article-1">Next</a>
const { $mu } = collect.scope('project-2');
// Creates a collector scoped to `project-2` and mutates it.
$mu('.next', 'next').text('Article 1');
The link now has a scoped class name and the text has been changed.
<a class="next mutate-project-2-next">Article 1</a>