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 🙏

© 2026 – Pkg Stats / Ryan Hefner

asgc-observer

v1.0.1

Published

asgc-observer

Readme

欢迎使asgc-observer

asgc-observer是傲世孤尘开源的一个消息库,通过接口定义消息,发布消息,可以拿到消息订阅者的返回值,实现方法的消息式调用。特点概述:

  • 使用简单 :一行代码可完成消息的订阅、消息的发布。
  • 例程丰富 :对于本工具的使用提供了详细的示例程序。

如何使用asgc-observer

1、安装模块

npm install asgc-observer

2、引入模块

var $ = require('asgc-observer');

3、jquery风格使用

var $ = require('asgc-observer'); 

//如果你是用过jquery,那么相信下面的写法你一定不会陌生
$('#btnSuccess').on('click',function(a,b){
	console.log('#btnSuccess click1',a,b);
});

//同一个事件可以有多个方法一起监听
$('#btnSuccess').on('click',function(a,b){
	console.log('#btnSuccess click2',a,b);
});

//参数个数不限
$('#btnSuccess').trigger('click','参数1','参数2');

//上面的语法与jquery一模一样
//唯一的区别是,$()括号中的字符串仅仅是个字符串,事件名click也仅仅是
//个字符串,并没有真正对应的dom对象以及点击事件。
//请记住,这个库不是用来与前端交互的。它仅仅是语法类似而已。
//因此$()括号中的字符串可以任意设置,用于区分不同的上下文环境。
//事件名(也可以叫做消息名称)也可以任意设置,用于逻辑上的区分

3.1、输出结果

#btnSuccess click1 参数1 参数2
#btnSuccess click2 参数1 参数2

4、方法的消息式调用

var $ = require('asgc-observer');

//除了以上,本库还提供了其他几个方法如下:
$('calc').on('add',(a,b) => a + b);
$('calc').on('sub',(a,b) => a - b);
$('calc').on('mul',(a,b) => a * b);
$('calc').on('dev',(a,b) => a / b);

//测试某个上下文下是否有监听某个事件(订阅某个消息)
console.log($('calc').test('add'));
console.log($('calc').test('sqrt'));

//触发事件(现在是不是感觉叫事件有点别扭?)
//从现在开始我们可以称之为方法的消息式调用。
console.log($('calc').trigger('add',3,2));
console.log($('calc').trigger('sub',3,2));
console.log($('calc').trigger('mul',3,2));
console.log($('calc').trigger('dev',3,2));

4.1、输出结果

true
false
5
1
6
1.5

5、其他的玩法

var $ = require('asgc-observer');

(() => {
	$.on('calc',(a,b) => a + b);
	$.on('calc',(a,b) => a - b);
	$.on('calc',(a,b) => a * b);
	$.on('calc',(a,b) => a / b);

	$.on('hello',name => 'hello ' + name + '!');

	//当存在多个执行器,返回一个结果数组
	console.log($.trigger('calc',8,4));
	//如果只存在一个,则直接返回结果。
	console.log($.trigger('hello','zhangsan'));
})();

(() => {
	$.on('solve',n => n*2);
	$.on('solve',(n,res) => res+1);
	$.on('solve',(n,res) => res*res);

	//分步处理(n*2 + 1)^2
	console.log($.triggerChain('solve',1));
})();

(() => {
	$.on('bb',function(){
		throw new Error('运行异常!');
		return '第一个bb';
	});
	$.on('bb',() => '第二个bb');
	$.on('bb',() => '第三个bb');

	//如果执行错误,则继续执行下一个,返回第一个执行成功的结果,并结束。
	console.log($.triggerOne('bb'));
})();

5.1、输出结果

[ 12, 4, 32, 2 ]
hello zhangsan!
9
第二个bb

asgc-observer相关

asgc-operator

asgc-observer是傲世孤尘开源的一个运算符定义工具,它内置了一些常见的数学运算(+、-、*、/、...),并且通过接口可以扩展我们自己的运算符,带来前所未有的编程体验。

asgc-lisen

asgc-lisen是傲世孤尘开源的一个监听变量值、表达式变化的库。基于这个库,笔者已实现一个前段双向绑定的工具。类似于vue、angularjs。

###asgc-web asgc-web是傲世孤尘开源的一个nodejs web容器,mvc框架。实现了后端路由、请求分发、参数解析、前端模板渲染等等。

联系我们

笔者QQ 1052045476 nodejs交流群 527393872 java交流群 527393872 c/c++语言交流群 251975693