# eilmer

> Eilmer is an MVVM toolkit for React

Latest version **0.0.1** (published 2022-05-20) · UNLICENSED license · 0 weekly downloads

## Install

```sh
npm install eilmer
pnpm add eilmer
yarn add eilmer
bun add eilmer
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2022-05-20 |
| First published | 2022-05-20 |
| Weekly downloads | 0 |
| License | UNLICENSED |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 2.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Darren Scott |
| Maintainers | mrdigs |
| Keywords | MVVM, React |

## Links

- npm: https://www.npmjs.com/package/eilmer
- npm.io page: https://npm.io/package/eilmer

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.1 (latest) — 2022-05-20

## README

# Eilmer MVVM
Eilmer is a toolkit for building MVVM applications and frameworks, specifically targeted for (but not limited to) **React**.

| :warning: | Eilmer is currently in development and there is no code contained in this package at the moment. The initial release is expected in the coming weeks.
| - |:-|

## Example Code
The following code gives a good overview of the capabilities of Eilmer. Full documentation will be provided on release.

### The Model
```javascript
  class PersonModel {
    firstName
    lastName

    constructor(firstName, lastName) {
      this.firstName = firstName
      this.lastName = lastName
    }

    hasName(firstName, lastName) {
      return firstName === this.firstName && lastName === this.lastName
    }

    async setName(firstName, lastName) {
      this.firstName = firstName
      this.lastName = lastName
      // await some REST API call, etc
    }
  }
```
### The View Model
```javascript
  class PersonViewModel {
    #personModel
    firstName
    lastName

    constructor(personModel) {
      this.#personModel = personModel
      this.firstName = this.#personModel.firstName
      this.lastName = this.#personModel.lastName
      this.save.canExecute = false
    }

    onPropertyChange() {
      this.save.canExecute = (
        !this.#personModel.hasName(this.firstName, this.lastName)
        && this.firstName && this.lastName
      )
    }

    onSaved() {
      this.save.canExecute = false
    }

    async save() {
      this.#personModel.setName(this.firstName, this.lastName)
      this.onSaved()
    }
  }
```
### The View
```javascript
import { Binder, useEvent } from 'eilmer/react'
import { notConverter } from 'eilmer/converters'

  const personModel = new PersonModel('', '')
  const personViewModel = new PersonViewModel(personModel)

  function PersonView({ viewModel = personViewModel }) {
    useEvent(viewModel, 'onSaved', () => {
      alert('Successfully saved!')
      return true
    })

    return <>
      <div>Model Value: {JSON.stringify(personModel)}</div>
      <Binder.Binding vm={viewModel} value="firstName">
        <input/>
      </Binder.Binding>
      <Binder.Binding vm={viewModel} value="lastName">
        <input/>
      </Binder.Binding>
      <Binder.Binding vm={viewModel} command="save" canExecute={['disabled', notConverter]}>
        <button>Save</button>
      </Binder.Binding>
    </>
  }
```

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