Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

callstackjs

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

callstackjs

JavaScript call stack controller

  • 0.3.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

callStack

JavaScript call stack controller.

API

  • callStack.add(ctx:Object, fn:String, options:Object)
  • callStack.wrap(fn:Function):Function
  • callStack.wrap(ctx:Object, fn:String):Function
  • callStack.wrap(ctx:Object, fn:Function):Function
  • callStack.wrap(ctx:Object, fn:String, options:Object):Function
  • callStack(name:String):Stack — get call stack by name
  • callStack.order(firstName:String, secondName:String[, etc])
  • callStack.pause()
  • callStack.unpause()
  • callStack.clear(name:String)
  • callStack.override(ctx:Object, method:String, callback:Function):Function

Use case

var MyView = framework.View.extend({
    initialize: function (){
		callStack('vis').wrap(this, 'visibility');
		callStack('render').wrap(this, 'render', { uniq: 'once' });
	},

	visibility: function (state){
		console.log(this.id+'.vis:', state);
		this.$el.css('display', state ? '' : 'none');
	},

	render: function (){
		console.log(this.id+'.render');
		this.$el.empty().html( ... );
	}
})


callStack.order('render', 'vis');

var viewHeader = new MyView({ id: 'header' });
var viewContent = new MyView({ id: 'content' });
var viewFooter = new MyView({ id: 'footer' });


// (1) Somewhere in the code.
viewHeader.visibility(true);
viewContent.visibility(true);
viewFooter.visibility(true);

// (2)
viewFooter.render(); // (!)
viewHeader.render();
viewContent.render();

// (3)
viewFooter.visibility(false);
viewFooter.render(); // (!!)

Next tick: console

header.render
content.render
footer.render

header.vis: true
content.vis: true
footer.vis: true
footer.vis: false

callStack.override

var module = {
	name: "callStack",
	toString: function (){
		return this.name;
	}
};

module.toString(); // "callStack"

// Owerride `toString` method
callStack.override(module, 'toString', function (toStringFn/**Function*/){
	retrun function (){
		return '['+ toStringFn.call(this) +']';
	};
});

module.toString(); // "[callStack]"

Options

Option:wieght (default = 0)

var foo = callStack.wrap(function (){ console.log("foo:", arguments) }, { weight: 100 });
var bar = callStack.wrap(function (){ console.log("bar:", arguments) }, { weight: 10 });

bar(1);
foo(1);
bar(2);
foo(2);

Console:

foo: 1
foo: 2
bar: 1
bar: 2

Option:uniq

var foo = callStack.wrap(function (){ console.log("foo:", arguments) }, { uniq: true, weight: 100 });
var bar = callStack.wrap(function (){ console.log("bar:", arguments) }, { uniq: "once" });

foo(1);
bar(1);
foo(2);
foo(2);
bar(1)

bar(1);
foo(3);
foo(3);
foo(1);
bar(5);

Console:

foo: 1
foo: 2
foo: 3
foo: 1
bar: 5

Keywords

FAQs

Package last updated on 16 Sep 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc