# lu-scope
`lu-scope` is the primary directive in Lune. It marks a region of the DOM that should be controlled by Lune.
## Usage
### Inline Scope
You can pass a JavaScript object directly to `lu-scope` to define the initial state:
```html
{{ count }}
```
> [!TIP]
> The expression inside `lu-scope` is evaluated once when the component is initialized. It should return an object.
### Server-Side Data Injection
One of the most powerful features of `lu-scope` is initializing it with data from your backend.
```html
Welcome, {{ user.name }}
```
This allows you to pass initial state directly from your database without making an extra API call.
### Explicit Mount Target
If you don't use the `init` attribute on the script tag, you can manually mount Lune to specific elements. In this case, `lu-scope` serves as a marker.
```html
{{ count }}
```
### Multiple Roots
A page can carry as many `lu-scope` regions as you like. Each one gets its own scope, and sibling regions are independent of each other:
```html
Region 1: {{ count }}
Region 2: {{ count }}
```
When Lune auto-mounts (or you call `mount()` without a target), every top-level `lu-scope` on the page becomes a root of the _same_ app instance — nested `lu-scope` elements are left to their parent region. Call `createApp()` more than once only when you want separately mounted apps, each with its own root data and directives.
## Scope Inheritance
Nested `lu-scope` regions create nested scopes. Child scopes can access properties from parent scopes, but writing to a property will check the current scope first.
```html
{{ outer }}
{{ outer }} - {{ inner }}
```
## Best Practices
### Function Factories
For anything more complex than a simple counter, it is recommended to use a function to return the initial state. This keeps your template clean and allows for reusable logic.
The factory has to be reachable from the expression, and a function declared in a `
{{ count }}
```
`allowGlobals({ Counter })` is the alternative when a factory is shared by several apps. See
[Security](/advanced/security#application-globals).
### Grouping Components
Passing one namespace object keeps the root data tidy when a page has several components:
```html