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

massive-web

v2.0.0-rc1

Published

Manage your js components

Downloads

2,224

Readme

CircleCi npm Size Install Size

Web JS

The web-js in connection with web component twig extension gives you simple and efficient way to handle your javascript components over twig.

Installation

Yarn

yarn add massive-web

NPM

npm install massive-web

Usage

Create your first component

A component can be created using different js patterns:

Using Revealing pattern

// js/components/test-revealing-pattern.js
var $ = require('jquery');

module.exports = (function() {
    var test = {};

    test.initialize = function(el, options) {
        test.text = options.text;
        $(el).click(test.say.bind(this));
    };

    test.say = function() {
        alert(test.text);
    }

    return {
        initialize: test.initialize,
        say: test.say
    };
});

Using Prototype pattern

// js/components/test-prototype-pattern.js
var $ = require('jquery');

var test = function() {};

test.prototype.initialize = function(el, options) {
    this.text = options.text;
    $(el).click(this.say.bind(this));
};

test.prototype.say = function() {
    alert(this.test);
};

module.exports = test;

Using ECMAScript 2015 class

// js/components/test-class.js
import $ from 'jquery';

export default class Test {
    constructor() {
        this.text = '';
    }

    initialize(el, options) {
        this.text = options.text;
        $(el).click(this.say);
    }

    say() {
        alert(this.text);
    }
}

Create your first service

Sometimes you want just run js code which is not binded to a dom element for this services where created. Typically usages are running tracking code functions.

// js/services/log.js

module.exports = {
   log: function(text) {
       console.log(text);
   }    
};

Initialize web.js and registering your components and services

// js/main.js
var web = window.web = require('massive.web');

// services
web.registerService('logger', require('./services/log.js'));

// components
web.registerComponent('test', require('./components/test-revealing-pattern.js'));
web.registerComponent('other', require('./components/test-prototype-pattern.js'));
web.registerComponent('more', require('./components/test-class'), { defaultOption: 'defaultValue' });

When using ES6:

import web from 'massive-web';
import Test from './components/test'
import Other from './components/more'
import Log from './services/log';


// services
web.registerService('logger', Log);

// components
web.registerComponent('test', Test);
web.registerComponent('more', Test, { defaultOption: 'defaultValue' });

Embedding in template

For efficient handling its recommended to use it with a template engine like twig.

Twig

For twig embedding see the web component twig extension.

HTML

You can also use without a template engine and by calling the startComponents and callServices.

<button id="test-1">
    Say Hello
</button>

<button id="test-2">
    Say Bye
</button>

<script src="js/main.js"></script>
<script>
    web.startComponents([
        {name: 'test', id: 'test-1', { text: 'Hello' }}, 
        {name: 'test', id: 'test-2', { text: 'Bye' }}
    ]);
    
    web.callServices([
        {name: 'logger', func: 'log', args: ['Hello']}
    ]);
</script>

Version Update & Publish to NPM (docs for maintainers)

1. Create release on github

Update package.json version on master branch:

git checkout master
git pull origin master
npm version [ major | minor | patch ] --no-git-tag-version
# update version in changelog
git add .
git commit -m "Release <version>"
git push origin master

Generate changelog:

github_changelog_generator --future-release <version>

Copy the text of the last release into github release description and create new release.

2. Publish release

git fetch --tags
git checkout <version>
# Test which files get packed by npm
npm pack --dry-run
# Publish package
npm publish