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

@jusfoun-vis/common

v0.1.1

Published

JavaScript Common Library.

Downloads

3

Readme

JavaScript Common Library

Jusfoun Visualization Department.

forge/forge2 混合继承

forge/forge2用于混合继承对象,其中forge用于ES6,forge用于ES5。

class ClassA {
}
class ClassB {
}
class ClassC extends ClassB {
}
forge(ClassC, ClassA);
var ClassA = function () {
};
var ClassB = function () {
};
var ClassC = function () {
};
ClassC.prototype = forge2(ClassB.prototype, ClassA.prototype, {});

EventDispatcher 事件派发器

EventDispatcher实现观察者模式,可用于任意需事件监听的场合。

import {EventDispatcher} from '@jusfoun-vis/common';
class ClassA extends EventDispatcher {
}

const a = new ClassA();
a.on('event1', function (e) { console.log(e); });
a.fire({ type: 'event1' });
a.off('event1');

Timer 定时器

Timer可用于任意需定时调用的场合。

import {Timer} from '@jusfoun-vis/common';

// 每秒执行一次,永不停止。
var timer = new Timer(1000);
timer.on('timer', function () { console.log(1); });
timer.start();

// 以屏幕刷新率执行,永不停止。
var timer = new Timer(Timer.REQUEST_ANIMATION_FRAME);
timer.on('timer', function () { console.log(1); });
timer.start();

// 每秒执行一次,执行10次便停止,在停止后,若不重置定时器,则启动会立刻停止。
var timer = new Timer(1000, 10);
timer.on('timer', function () { console.log(1); });
timer.start();

// 停止、重置、取消事件。
timer.stop();
timer.reset();
timer.off('timer');

UiComponent 元件基类

UiComponent实现基于Tick-tock形式的属性变更优化模型,可实现属性批量提交,达到优化性能的目的。

import {UiComponent} from '@jusfoun-vis/common';

class ClassA extends UiComponent {
  constructor() {
    super();
    this._count1 = 0;
    this._count2 = 0;
  }
  
  _invalidate1Flag = false;
  set paramA(value) {
    this._paramA = value;
    this._invalidate1Flag = true;
    this.invalidateProperties();
  }
  set paramB(value) {
    this._paramB = value;
    this._invalidate1Flag = true;
    this.invalidateProperties();
  }
  _invalidate2Flag = false;
  set paramC(value) {
    this._paramC = value;
    this._invalidate2Flag = false;
    this.invalidateProperties();
  }
  set paramD(value) {
    this._paramD = value;
    this._invalidate2Flag = false;
    this.invalidateProperties();
  }
  
  commitProperties() {
    if (this._invalidate1Flag) {
      this._invalidate1Flag = false;
      // redraw for paramA and paramB
      this._count1++;
    }
    
    if (this._invalidate2Flag) {
      this._invalidate2Flag = false;
      // redraw for paramC and paramD
      this._count2++;
    }
  }

  measure() {
  }

  updateDisplayList() {
  }
}

const a = new ClassA();
for (let i = 0; i < 10000; i++) {
  a.paramA = ...
  a.paramB = ...
  a.paramC = ...
  a.paramD = ...
}
console.log(a._count1, a._count2); // output: 1 1

ElementUtil 元素工具

ElementUtil提供常用的元素处理方法集。

import {
  createElement,
  createElementNS,
  getAttribute,
  setAttributes,
  setStyles,
  
  SVG_NS
} from '@jusfoun-vis/common';

// 创建元素
const canvas = createElement('canvas');
const svg = createElementNS('svg', SVG_NS);

// 批量设置元素属性
setAttributes(canvas, {
  width: 1024,
  height: 1024
});

// 批量设置元素样式
setStyles(canvas, {
  position: 'absolute',
  left: '128px',
  top: '256px'
});