# Classic `import` support

Memorio supports two equivalent styles: the original global side-effect import,
and the new named exports. Both share the same instances (one source of truth).

```typescript
// Global style (original)
import 'memorio'
state.user = { name: 'Sara' }

// Classic import style (new)
import { state } from 'memorio'
state.user = { name: 'Sara' }
```

`state` in both examples is the exact same Proxy object.

---

## Why two styles?

| Style | When to use |
|-------|-------------|
| `import 'memorio'` | Zero-config, global access everywhere, legacy scripts |
| `import { state } from 'memorio'` | Explicit dependencies, tree-shakeable bundles, TypeScript IntelliSense |

---

## ESM named imports

All modules are available as named exports:

```typescript
import {
  state,
  store,
  session,
  cache,
  idb,
  observer,
  useObserver,
  dispatch,
  message,
  devtools,
  logger
} from 'memorio'
```

Platform helpers:

```typescript
import {
  isBrowser,
  isNode,
  isDeno,
  isEdge,
  getCapabilities,
  createContext,
  listContexts,
  deleteContext
} from 'memorio'
```

Internal utilities (for tests/debug):

```typescript
import internal, { propertyName } from 'memorio'
import { setContext, getContext } from 'memorio'
```

Default export (the public `memorio` namespace):

```typescript
import memorio from 'memorio'
memorio.help()
```

---

## CJS usage

```javascript
const { state, store, memorio } = require('memorio')
```

---

## React / useObserver

`useObserver` works the same way via named import:

```tsx
import { useObserver, state } from 'memorio'

function Counter() {
  const [, forceUpdate] = useReducer(x => x + 1, 0)

  useObserver(forceUpdate, [state.counter])

  return <div>Count: {state.counter}</div>
}
```

---

## Context isolation

```typescript
import { createContext, listContexts, deleteContext, isolate } from 'memorio'

const ctx = createContext('tenant-123')
ctx.state.user = { name: 'Isolated' }
ctx.store.set('settings', { theme: 'dark' })

listContexts() // ['tenant-123']
deleteContext('tenant-123')
```

---

## Same-instance guarantee

Named exports point to the same instances published on `globalThis` by
`core/global` at bootstrap. Mutating via named export mutates the global,
and vice versa.

```typescript
import { state } from 'memorio'

state.importedFlag = true
console.debug(globalThis.state.importedFlag) // true
```

---

## Migration from global-only

No code changes required. Existing `import 'memorio'` + `state.foo = 1`
continues to work unchanged. Named exports are additive.
