# marko-real-state

> Marko (v3) Real State ===========================

Latest version **1.0.3** (published 2019-01-31) · ISC license · 0 weekly downloads

## Install

```sh
npm install marko-real-state
pnpm add marko-real-state
yarn add marko-real-state
bun add marko-real-state
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2019-01-31 |
| First published | 2019-01-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 26 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Chris Cinelli |
| Maintainers | ccinelli |
| Keywords | marko3, marko, markov3, v3, real, state, realstate |

## Links

- npm: https://www.npmjs.com/package/marko-real-state
- Repository: https://github.com/ccinelli/marko-real-state
- Homepage: https://github.com/ccinelli/marko-real-state#readme
- Issues: https://github.com/ccinelli/marko-real-state/issues
- npm.io page: https://npm.io/package/marko-real-state

## Alternatives

- [@reckona/mreact-store](https://npm.io/package/@reckona/mreact-store.md) — 976 weekly downloads
- [regular-state](https://npm.io/package/regular-state.md) — 410 weekly downloads
- [@pacote/flux-actions](https://npm.io/package/@pacote/flux-actions.md) — 65 weekly downloads
- [@pilotlab/lux-debug](https://npm.io/package/@pilotlab/lux-debug.md) — 39 weekly downloads
- [vue-persist-state](https://npm.io/package/vue-persist-state.md) — 19 weekly downloads

## Recent versions

- 1.0.3 (latest) — 2019-01-31
- 1.0.2 — 2019-01-31
- 1.0.1 — 2019-01-31
- 1.0.0 — 2019-01-29

## README

Marko (v3) Real State
===========================

This module lets you to create components with "real states" that persist during parent's re-renders

# Why
Marko 3 has an unusual way to dal with states. When a parent re-render the `getInitialState` function of the child component is called in the children and they lose their state.

This let you persist the state across re-renders.

# Installation
```
npm install marko-real-state
```
Or 
```
yarn add marko-real-state
```

# Use

```javascript
const realState = require('../../lib');
 
// Notice the `defineComponent(` *`realState`* `({`
module.exports = require('marko-widgets').defineComponent(realState({
    // This is called only once and it will
    // override variables declared in getInitialState
    // What this function returns  will persist when
    // the parent state is updated and the component has to re-render
    // You can keep using this.setState as usual to update the state
    
    getInitialRealState: function(input) {
        var value = input.value || 0;
        return {
            value: value
        };
    },
    ...
```

# Sample app

#### Download it:

```
git clone https://github.com/ccinelli/marko-real-state.git
cd marko-real-state
# Run with this: [or browser-refresh server.js]
node server.js
```

#### The app will start with all counters at 0:

![step0](https://user-images.githubusercontent.com/38021940/51940298-7aaa7900-23c6-11e9-8a24-77bea041536f.png)

#### Increment the 2 children

![step1](https://user-images.githubusercontent.com/38021940/51940306-7da56980-23c6-11e9-8eae-2240fbc68141.png)

#### Increment the parent

![step2](https://user-images.githubusercontent.com/38021940/51940315-826a1d80-23c6-11e9-9ee2-ba72331b655c.png)

#### The child with realState maintains its state

# TODO

- Tests

---
_Source: https://npm.io/package/marko-real-state · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
