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

trampoline-framework

v0.9.0

Published

A TypeScript framework for making me feel great about having developed a framework.

Downloads

14

Readme

trampoline-framework

A TypeScript framework for making me feel great about having developed a framework.

Usage

yarn add trampoline-framework
npm install trampline-framework

import { ... } from 'trampoline-framework';

// ...

Decorators

@Bound

A class and class method decorator decorator which binds instance methods to instance contexts. When applied to a class, all methods are context-bound.

@Bound class View {
  public onButtonClick (): void { }
  public onOptionClick (): void { }
  public onLinkClick (): void { }
}
class A {
  public prop: any;

  @Bound public assignProp (prop: any): void {
    this.prop = prop;
  }
}

@Final

A class and class method decorator which prevents extension and subclass overrides, respectively.

@Final class A { }

// Throws Error in strict mode
class B extends A { }

// Throws Error in non-strict mode
const b: B = new B();
class A {
  @Final public method (): void { }
}

class B extends A {
  // Throws Error
  public method (): void { }
}

@Implements

A method decorator which merely labels a method as an implementation for an interface or abstract class method. If a superclass already implements the decorated method, an Error is thrown.

class Service implements IFetchable {
  @Implements public fetch (): Promise<any> {
    // ...
  }
}

@Override

A method decorator which merely labels a method as an override for a superclass method. If the superclass lacks the corresponding method, an Error is thrown.

class AppView extends View {
  @Override public onRender (): {
    // ...
  }
}

@Automated

A class decorator which enables methods to be decorated with @Run() or @Poll().

@Automated class A { }

@Run()

A method decorator which runs decorated instance methods at class instantiation, and decorated static methods at runtime. Arguments can be provided to the decorator to call the targeting method with. Decorated methods must be on an @Automated class.

@Automated class A {
  @Run()
  public init (): void { }
}

@Automated class B {
  @Run(Date.now())
  public static init (time: number): void {
    // ...
  }
}

@Poll()

A method decorator which repeatedly runs decorated instance methods at class instantiation, and decorated static methods at runtime. A polling interval, measured in milliseconds, can be specified as the decorator argument, which defaults to 1000. Decorated methods must be on an @Automated class.

@Automated class A {
  @Poll(500)
  public check (): void { }
}

@Automated class B {
  @Poll(100)
  public static check (): void { }
}

@Wired

A class decorator which enables all @Autowired() properties or method parameters to be autowired at instantiation or when the applicable method is called, respectively.

@Wired class A { }

@Autowired

A property and parameter decorator which allows values to be autowired (automatically provided with new instances) at runtime (static-side properties), class instantiation time (instance-side properties), or method call time (parameters). Classes which contain autowired properties or method parameters must also be decorated with @Wired.

Arguments can be provided to the decorator to be passed into autowired instances on construction.

@Wired class DAO {
  @Autowired() public service: Service;
}

@Wired class DAO2 {
  public fetch (@Autowired('route/to/api.svc') service: Service): {
    return service.fetch();
  }
}

@Wired class StaticDAO {
  @Autowired() public static service: Service;
}

@PreventDefault

Prevents default event behavior for events passed into decorated class method event handlers.

class View {
  @PreventDefault
  public onClick (e: Event): void { }
}

@StopPropagation

Stops event propagation from decorated class method event handlers.

class View {
  @StopPropagation
  public onClick (e: Event): void { }
}

@SuppressEvent

Composes @StopPropagation and @PreventDefault into a single decorator.

class View {
  @SuppressEvent
  public onClick (e: Event): void { }
}

@Unfinished

Stubs decorated methods, or all instance and static methods on decorated classes, with an optional warning message and a thrown Error.

class A {
  @Unfinished('Not done yet.')
  public getValue (): void { }
}
@Unfinished('Still needs work.')
class A {
  public field: string;

  public getField (): void { }
}

Resource classes

Singleton

A class which provides Singleton pattern behavior to extending classes. Contention about Singletons aside, this at least saves the trouble of implementing the pattern for every Singleton class.

class A extends Singleton { }

// Throws Error
const a: A = new A();

const a: A = A.getInstance();

EventManager

A custom event handler container and dispatcher.

const eventManager = new EventManager();

function handler () { }
function handler2 (data: any) { }

eventManager.on('event', handler);
eventManager.on('event-2', handler2);
eventManager.trigger('event');
eventManager.trigger('event-2', { data: 'object' });
eventManager.off('event', handler);
eventManager.off('event');
eventManager.off();

Data structures

Map

import { Map } from 'trampoline-framework';

const map = new Map<string, number>();

map.set('hello', 5)
map.get('hello') // 5
map.size // 1
map.entries() // [ [ 'hello', 5 ] ]
map.keys() // [ 'hello' ]
map.values() // [ 5 ]
map.has('hello') // true

map.forEach((value: number, key: string, map: Map<string, number>) => {
  // ...
})

map.delete('hello')

map.set('hi', 1)
map.set('bye', 2)

map.clear()
map.size() // 0

MultiMap

import { MultiMap } from 'trampoline-framework';

const multiMap = new MultiMap<string, number>()

multiMap.put('hello', 1)
multiMap.put('hello', 2)
multiMap.put('hello', 3)
multiMap.size // 1
multiMap.has('hello') // true
multiMap.get('hello') // [ 1, 2, 3 ]

multiMap.forEach((values: number[], key: string, multiMap: MultiMap<string, number>) => {
  // ...
})

multiMap.remove('hello', 2)
multiMap.get('hello') // [ 1, 3 ]
multiMap.remove('hello')
multiMap.size // 0

multiMap.put('hi', 1)
multiMap.put('hi', 2)
multiMap.put('bye', 3)
multiMap.put('bye', 4)

multiMap.entries(); // [ ['hi', [1, 2]], ['bye', [3, 4]] ]
multiMap.clear()

multiMap.size // 0