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

mivm

v1.0.1

Published

A tiny mvvm library for fun. Use snabbdom.js for virtual dom.

Downloads

2

Readme

Mivm

A tiny mvvm library for fun. Use snabbdom.js for virtual dom.

This plugin is just built for learning & memoing purpose.

Do not use in your production.

Install

$ npm install mivm
$ yarn add mivm

Usage

Create root app

Use renderApp with a function or options to create root app, then mount it to DOM.

import { renderApp } from 'mivm';

const app = renderApp(({ html }) =>
  html`<div id="app">Hello App</div>`
).mount('#app');

Create component

Use setup to create a component for compiler to deal with.

Components can be used with options components, then used in render function.

// MyButton
import { setup } from 'mivm';

export default setup(
  ({ html }) => html`<button>My Button</button>`
);
// Use in root
import { renderApp } from 'mivm';
import MyButton from './MyButton';

const app = renderApp({
  components: {
    MyButton
  },
  render({ html }) {
    return html`
      <div id="app">
        Hello App
        <MyButton></MyButton>
      </div>
    `;
  }
}).mount('#app');
// Use in another component
import { setup } from 'mivm';
import MyButton from './MyButton';

export default setup({
  components: {
    MyButton,
  },
  render({ html }) {
    // ...
  }
})

Create reactive state

Use data option with ref, reactive, watchEffect function, then return them.

get returned object by render function's 2nd argument.

import { setup } from 'mivm';

export default setup({
  data({ ref }) {
    const msg = ref('World');
    return { msg };
  },
  render({ html }, state) {
    // get state
    const { msg } = state;
    return html`
      <div class="message">
        Hello ${msg.value}
      </div>
    `;
  }
});

Add event

Add event with @ startWith, eg. @click, @input, @keyup

export default setup({
  data({ ref }) {
    const inputText = ref('');
    const inputHandler = function(e) {
      inputText.value = e.target.value;
    };
    return { inputText, inputHandler };
  },
  render({ html }, state) {
    const { inputText, inputHandler } = state;
    return html`
      <div>
        This is Test: ${inputText.value}
        <input value="${inputText.value}" @input="${inputHandler}" />
      </div>
    `;
  }
});

Demo

Use parceljs for example

<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app"></div>

  <script src="index.js"></script>
</body>
</body>
</html>
// index.js
import { renderApp, setup } from 'mivm';

// component 1
const Test = setup({
  data({ ref }) {
    const inputText = ref('');
    const inputHandler = function(e) {
      inputText.value = e.target.value;
    };
    return { inputText, inputHandler };
  },
  render({ html }, state) {
    const { inputText, inputHandler } = state;
    return html`
      <div class="test">
        This is Test: ${inputText.value}
        <input value="${inputText.value}" @input="${inputHandler}" />
      </div>
    `;
  }
});

// component 2
const Test2 = setup(({ html }) => html`
  <div class="test2">Hello Test2</div>
`);

const app = renderApp({
  components: {
    Test,
    Test2
  },
  data({ ref }) {
    const count = ref(0);
    const increment = () => {
      count.value += 1;
    };
    return { count, increment };
  },
  render({ html }, state) {
    return html`
      <div id="app">
        ${state.count.value}
        <p @click="${state.increment}">Hello World</p>
        <Test></Test>
        <Test2></Test2>
      </div>
    `;
  },
}).mount('#app');

console.log(app);