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

vc-cake

v1.1.2

Published

Modular approach for javascript based projects from WPBakery

Downloads

46

Readme

vcCake · Build Status

vcCake is a small JavaScript library to use modular approach for building all types of apps.

VcCake application is managed by the VcCake object, whose job is to manage modules and services. It's the combination of objects that allow you to build a scalable Js front-end.

What you can do with it. vcCake allows to communicate modules with each other or even group objects in one scope without tight coupling. It is good for tests, because you can substitute any part or the system with a mockups and emulate interaction with modules with another module.

APP
 |__ Services
 |__ Module Scope
 	|__ Module clouser
 	|__ Module clouser
 	|__ ...

Application has two ways for interactions:

  • request/reply or global scope events
  • notify/on or module scope events

Every module recieves has an access to limited api with a list of posible methods.

Service

Globally accessible object that can be used by all modules in all scopes. Example: key generators, i18n functions, default settings for new elements, template for element.

vcCake.addService('service-name', {
	uniqID: function() {...},
	anotherMethod: function(){..},
	listOfData: [1,2,3],
	...
});

Module

A part of the page(not always visible part of the page, but it has owen independent logic from all othe elements of the project). Some modules can be coupled via modules API.

App API methods for Module clouser

  • request(eventName, data) - global request to system that module required any reply from any module;
  • reply(eventName, fn) - subscribe to global request from module, module scope can be the same;
  • addAction(actionName, fn) - create public function to work with module;
  • notify(eventName, data) - publish module event;
  • on(eventName, fn) - subscribe to event inside module scope;
    • do(actionName, ..atts) - call module action;
  • once(eventName, fn) - subscribe to event inside module scope but react on event only once;
  • actions.{actionName} - accessor to actions function inside module scope;
  • module(moduleName) - returns another Module API with limited amount of methods;
    • on(eventName, fn) - subscribe to module event;
      • do(actionName, ..atts) - call module action;
    • once(eventName, fn) - subscribe to event but react on event only once;
    • actions - get list of accessible actions for a module;
vcCake.add('module-scope', function(api){
	
	// Like publish global events
	let data = api.service('service-name').methodToGetData();
	api.request('event-name', data);
	
	// Like subscribe global events
	api.reply('event-name', function(dataIfPassed){
		// ... here comes the event
	});
	
	// Create action of module which can be used to interact with module from another module.
	api.addAction('module-action-name', function(...attrsMaybePassed){
		// ...hre comes the action
	});
	
	// Like publish, module inner events
	api.notify('module-event-name', true); // this event inside module
	

	// Like subscribe, module inner events
	api.module('module-scope').on('module-event-name', function(){
		...
	});
	// or you can just call do to call action
	api
	    .module('module-scope')
	    .on('module-event-name')
	    .do('module-action-name', ...attrsMaybePassed);
});

Storage

Event-driven services allow storing states and trigger events.

To create storage call vcCake.addStorage(storageKey, fn) but it isn't required to create storage.

To use storage call vcCake.getStorage(storageKey).

App API methods for storage service

  • state(stateKey) - get state of the storage by key;
    • get() - get state value;
    • set(value) - set state value;
    • onChange(stateKey, fn) - subscribe callback function to state change;
    • ignoreChange(stateKey, fn) - unsubscribe callback function to state change;
    • delete(stateKey) - delete state;
  • on(eventName, fn) - subscribe to event;
  • off(eventName) - unsubscribe to storage event;
  • once(eventName, fn) - subscribe to event but react on event only once;
  • offOnce(eventName) - unsubscribe to storage once event;
  • trigger(eventName, data) - publish storage event;

You can use all these methods inside function callback when you create new storage via vcCake.addStorage(storageKey, fn).