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

good-typescript

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

good-typescript

Some good and useful implementations for TypeScript or JavaScript projects.

  • 0.5.0
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Build Status

Good

Some good and useful implementations for TypeScript or JavaScript projects.

Download

Directly from the master branch dist folder: https://github.com/SergioMorchon/Good-Typescript/tree/master/dist

Patterns

Here are some examples of the main patterns here.

Future

var async = new Good.Patterns.Future.Async<number, string, string>();

async.await().done((result: number) => {
	console.log(`done: ${result}`);
}).progress((value: string) => {
	console.log(`progress: ${value}`);
}).fail((error: string) => {
	console.log(`error: ${error}`);
}).always(() => {
	console.log("always");
});

async.notify("1");// "progress: 1"
async.notify("3");// "progress: 3"
async.notify("duck!");// "progress: duck!"

async.resolve(4);// "done: 4"
                 // "always"

Parallel Tasks

var task: Good.Patterns.Parallel.Task<string, void, string>,
    p1 = "task", p2 = "must", p3 = ["w", "o", "r", "k"];

task = new Good.Patterns.Parallel.Task<string, void, string>((async: Good.Patterns.Future.Async<string, void, string>, r1: string, r2: string, r3: string[]) => {
    async.resolve([r1, r2, r3.join("")].join(" "));
});

task.run(p1, p2, p3).done((result: string) => {
    console.log(result);// "task must work"
});

Contract

Good.Patterns.Contract.requires(true);// ok
Good.Patterns.Contract.requires(false, "contract violation");// throws a PreConditionError
Good.Patterns.Contract.ensures(true);// ok
Good.Patterns.Contract.ensures(false, "contract violation");// throws a PostConditionError

Namespace

var myModule: any = {},
    path: Object;

path = Good.Patterns.Namespace.extend(myModule, "with.a.namespace");
typeof myModule.with.a.namespace !== "undefined";// true

Command

var data = {
	add: function (s1: number, s2: number) {
		return s1 + s2;
	}
}, command = new Good.Patterns.Command.Invoker(data);

console.log(command.execute("add", 4, 6));// 10
command.execute("notExists");// throws an InvocationError

Mediator

 var group = new Good.Patterns.Mediator.Group(),
	error = "Some core error";

group.subscribe("core-error",(value: any) => {
	console.log(value);
});

group.publish("core-error", error);// "error"

Keywords

FAQs

Package last updated on 10 Feb 2015

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