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

v1.0.1

Published

Harness for vue components

Downloads

6

Readme

vue-harness

vue harnessing goodness

This is first swag at getting a harnessing system working for vue components and should not be viewed as a usable project at this time.

Standalone Mode

Basic Structures

export interface IHarnessOptions extends VueComponentOption {
    //A reference to a Vue component or function resolving a vue component (or component options)
    //this is optional if template is provided, otherwise required
     component? : (resolve : Thenable<VueApi>) => void | typeof Vue;
     //should the harness try to automatically map fields exposed in the vue `data` object to 
     //attributes in the template? (default true)
     autobindProps? : boolean;
     //a custom vue template string you can provided. this is required if component is not provided.
     //if you provide both, you can use the string COMPONENT in your template to inject the 
     //relevant component html (with attributes if autobindProps is true)
     template? : string;
     //optionally position the harness relative to the document body
     position? : 'left' | 'right' | 'center' | 'none';
     //optionally constrain the width of the harness (passed directly to the css width property of the parent div)
     width? : string,
     //a reference to the parent of this harness
     parentHarness? : Harness
}

Creating a harness

In order to use harness you need an element in the dom with the id harness-mount-point

var harness = new Harness('HarnessNameHere', harnessOptionsHere);

harness.use(); //applies the harness and mounts it at `harness-mount-point`, removing a previous harness if there was one

Harness.Use('HarnessNameHere'); //same as `use()` called on an instance

Harness.Get('HarnessNameHere'); //returns a harness instance if it exists

What can be harnessed?

A harness is just a Vue component with some wrapping around it, that means you can provide all the normal vue hooks, data fields, methods, mixins etc as you will. The only thing not respected is the el property.

var myComponent = Vue.component('my-component', {
    template: '<h1>Hi {{name}}</h1>',
    props: ['name']
});

var h = new Harness('MyComponent', <IHarnessOptions>{
    component: myComponent,
    data: function () {
        return {
            name: 'matt' //results in template <h1>Hi matt</h1> since props are set to autobind by default (using v-bind)
        }
    },
    created: function() {},  //normal vue hooks are usable
    methods: {fn: function(){}} //same goes for methods, watchers, mixins etc
});

Extending a harness

Harnesses can be extended, so any options provided to the parent are set on the child unless explicitly overridden

//this is still using the myComponent from the parent, output is now <h1>Hi Matthew</hi> since we override data.name
var h2 = h.extend('MyComponent2', <IHarnessOptions>{
    position: 'left', //override parent default of 'center'
    data: function () { //override parent data where name is 'matt'
        return {
            name: 'Matthew'
        }
    }
});

Using with vue-ts


var options = {width: '25%'}; //normal IHarnessOptions provided here

// add @harness to your class annotation before @VueComponent
@harness('ExampleHarness', options)
@VueComponent('example', '<p>im an example, hello {{name}}</p>')
export class Example extends VueApi {
    @prop public name : string;
}