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-logically

v1.0.0

Published

Logical components for increasing the readability of template conditionals and loops.

Downloads

90

Readme

vue-logically

Logical components for increasing the readability of template conditionals and loops.

Problem

You find the use of v-if and v-for attributes to indicate control flow in templates is obscure and unreadable. This is quite understandable - all other languages and frameworks you've grown up with have clearly visible block boundaries and familiar indentation.

Example: in EmberJS the logical flow can be seen from a distance, even if you squint your eyes:

{{#if this.isReady}}
    <p class="paragraph my-theme" data-test="content-paragraph-test">Ipsum lorem ... </p>
{{else}}
    <span>Sorry, not ready.</span>
{{/if}}

It doesn't matter how many attributes are on the <p> tag - it's far from the logical flow of the {{#if. Compared to VueJS:

<p v-if="isReady" class="paragraph my-theme" data-test="content-paragraph-test"></p>
<span v-else>Sorry, not ready.</span>

Problems with this:

  • The first thing you see are the html elements, before you even know if they're relevant under the condition, not the logic.
  • If you have many attributes, the v-if can get lost among them. Even worse if you list each attribute on new lines, they're indented! Imagine inverting your if block indentation in any other language!:
    • const isThisIsABadIdea = true;
      console.log('Yep, bad idea.')
         if (isThisIsABadIdea);            // Wait, what??
  • For multiple elements, you have to use awkward <template v-if> to block it out, using two different styles for one-vs-multiple. So lines for if, if else, else and for loops all start with the word "template" visually.

Possible Solution

Enforce a style policy to always use <template v-if and <template v-for (one element or otherwise) so that at least your indentation and control flow make sense.

This Solution

Go a step further and use the words you actually want to use at the beginning of those lines:

<If v-if="isReady">
    <p class="paragraph my-theme" data-test="content-paragraph-test">Ipsum lorem ... </p>
</If>
<Else v-else>
    <span>Sorry, not ready.</span>
</Else>
  • Indentation is right
  • Immediate reading of control flow
  • You don't have to use <template> elements for 5 different purposes.
  • You don't have to search for directives among lists of other similar-looking html attributes.

Usage

Install (Vue 3)

yarn add vue-logically

Install (Vue 2)

yarn add [email protected]

Include Globally

import VueLogically from 'vue-logically';

//...const app = createApp(...)
app.use(VueLogically);

The Components

These are the dumbest components around. Nothing prevents you from misusing them and mixing directives up. They are literally just a way to use a different label for <template>.

<If v-if="condition"></If>

<ElseIf v-else-if="condition"></ElseIf>

<Else v-else></Else>

<For v-for="item of list"></For>

Run yarn serve to see each one in use (./dev/serve.vue).

Development

yarn build

Serve the test application (dev/serve.js) on localhost:

yarn serve