0.0.15 • Published 6 years ago

@nuware/nitro v0.0.15

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

Nitro

Install

npm install @nuware/nitro --save

or

<script defer src="https://unpkg.com/@nuware/nitro@latest/dist/nitro.umd.js"></script>

or

<script defer src="https://unpkg.com/@nuware/nitro@latest/dist/nitro.umd.min.js"></script>

Usage

Browser

const { createSignal, createStore, combineStores } = window.nuware.Nitro

Node

const { createSignal, createStore, combineStores } = require('@nuware/nitro')

or

import { createSignal, createStore, combineStores } from '@nuware/nitro'

Exmaple

const setUser = createSignal()
const deleteUser = createSignal()
const deleteAllUsers = createSignal()

const users = createStore({})
users.reset(deleteAllUsers)
users.on(setUser, (state, payload) => {
  const { id, data } = payload
  return assoc(id)(data)(state)
})
users.on(deleteUser, (state, id) => {
  return dissoc(id)(state)
})

const usersCount = users.map((state) => {
  return keys(state).length
})

const onEmptyUsers = usersCount.map((state) => {
  return (state === 0)
})

users.watch((state) => console.log('Users:', state))
usersCount.watch((count) => console.log('Total Users:', count))
onEmptyUsers.watch(isEmpty => isEmpty && console.log('Users is empty!'))

const u1 = {
  id: 'id1',
  data: {
    name: 'User One'
  }
}

const u2 = {
  id: 'id2',
  data: {
    name: 'User Two'
  }
}

setUser(u1)
setUser(u2)

deleteUser(u1.id)
deleteAllUsers()

License

MIT License

Author

Dmitry Dudin dima@nuware.ru

0.0.15

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago