npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-tinybase-monorepo

v0.1.0

Published

**Warning**: This is a work-in-progress. Avoid using in production.

Downloads

5

Readme

Vue-TinyBase

Warning: This is a work-in-progress. Avoid using in production.

Please open github issues for any feature requests or questions.

Note: For all props marked as "reactive" - they accept values, functions that return values or references (including computed references)

Setup

Make sure you have a TinyBase store set-up.

1. Install vue-tinybase

npm install --save vue-tinybase

2. Connect TinyBase Store to Vue

This will be "default" store used by composables. If this store is not passed - you have to manually pass store as the last argument to every composable.

const app = createApp(App)

// store should be imported from where it is created
app.use(createTinybaseVue(store))

Usage

Composables

useStore

Returns the default store used in the "Connect TinyBase Store to Vue" step.

Note: This is not a ref, this comes a the store itself.

const store = useStore()

function setAsCompleted() {
  store.setCell('todos', rowId, 'completed', true)
}

useValues

Returns a readonly computed reference to all the values from a store.

Params:

  • store?: Store
<script setup>
import { useValues } from 'vue-tinybase'

const values = useValues()
</script>
<template>
  <h2>Store is {{ values.open ? 'open' : 'closed' }}</h2>
</template>

useValue

Returns a writable computed reference to a value from a store.

Params:

  • valueId: string (reactive)
  • store?: Store
<script setup>
import { useValue } from 'vue-tinybase'

const isOpen = useValue('open') // this is a boolean
</script>
<template>
  <button @click="isOpen = !isOpen">{{ isOpen ? 'Close' : 'Open' }}</button>
</template>

useTables

Returns a readonly computed reference to all the tables from a store.

Params:

  • store?: Store
<script setup>
import { useTables } from 'vue-tinybase'

const tables = useTables()
</script>

<template>
  <table>
    <thead>
      <tr>
        <th>Species</th>
        <th>Count</th>
        <th>Sold</th>
      </tr>
    </thead>
    <tbody>
      <tr v-for="(row, rowId) in tables.pets" :key="rowId">
        <td>{{ row.species }}</td>
        <td>{{ row.count }}</td>
        <td>{{ row.sold }}</td>
      </tr>
    </tbody>
  </table>
</template>

useTable

Returns a readonly computed reference to a table from a store.

Params:

  • tableId: string (reactive)
  • store?: Store
<script setup>
import { useTable } from 'vue-tinybase'

const pets = useTable('pets')
</script>

<template>
  <table>
    <thead>
      <tr>
        <th>Species</th>
        <th>Count</th>
        <th>Sold</th>
      </tr>
    </thead>
    <tbody>
      <tr v-for="(row, index) in pets" :key="index">
        <td>{{ row.species }}</td>
        <td>{{ row.count }}</td>
        <td>{{ row.sold }}</td>
      </tr>
    </tbody>
  </table>
</template>

useRow

Returns a readonly computed reference to a row from a table.

Params:

  • tableId: string (reactive)
  • rowId: string (reactive)
  • store?: Store
<script setup>
import { useRow } from 'vue-tinybase'

const props = defineProps(['rowId'])

const pet = useRow('pets', () => props.rowId)
</script>

<template>
  <tr>
    <td>{{ pet.species }}</td>
    <td>{{ pet.count }}</td>
    <td>{{ pet.sold }}</td>
  </tr>
</template>

useCell

Returns a writable computed reference to a cell from a store.

Params:

  • tableId: string (reactive)
  • rowId: string (reactive)
  • cellId: string (reactive)
  • store?: Store
<script setup>
import { useRow } from 'vue-tinybase'

const props = defineProps(['rowId'])

const isCompleted = useCell('todos', () => props.rowId, 'completed')
</script>

<template>
  <button @click="isCompleted = !isCompleted">
    {{ isCompleted ? 'Mark as completed' : 'Unmark as completed' }}
  </button>
</template>

Usage with TypeScript

Usage with typescript is only well-supported for a single store.

Check packages/examples/todolist-ts for a working example.

1. Expose type definitions

Expose your store type definitions to be imported elsewere. Here's a simple example: (also available in packages/examples/todolist-ts).

import { createStore } from 'tinybase/with-schemas'

export const store = createStore().setTablesSchema({
  todos: {
    text: { type: 'string' },
    completed: { type: 'boolean', default: false },
  },
})

export type Store = typeof store // this line exposes the type

2. Declare a typed module

Add to your global .d.ts a definition based on your store types.

declare module 'vue-tinybase/typed' {
  import type { Store } from '@/store' // import from your type definition
  import type {
    TypedUseCellFunction,
    TypedUseRowFunction,
    TypedUseStoreFunction,
    TypedUseTableFunction,
    TypedUseTablesFunction,
    TypedUseValueFunction,
    TypedUseValuesFunction,
  } from 'vue-tinybase'

  export const useStore: TypedUseStoreFunction<Store>
  export const useValues: TypedUseValuesFunction<Store>
  export const useValue: TypedUseValueFunction<Store>
  export const useTables: TypedUseTablesFunction<Store>
  export const useTable: TypedUseTableFunction<Store>
  export const useRow: TypedUseRowFunction<Store>
  export const useCell: TypedUseCellFunction<Store>
}

3. Add alias to your bundler

Alias vue-tinybase/typed to be resolved to vue-tinybase in your bundler.

Example with vite:

import { fileURLToPath, URL } from 'node:url'

import vue from '@vitejs/plugin-vue'
import { defineConfig } from 'vite'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      'vue-tinybase/typed': 'vue-tinybase',
    },
  },
})

4. Replace your imports

Import all composables from vue-tinybase/typed instead of vue-tinybase