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

@thi.ng/defmulti

Package Overview
Dependencies
Maintainers
1
Versions
186
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/defmulti - npm Package Compare versions

Comparing version 0.5.1 to 0.6.0

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

# [0.6.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/defmulti@0.5.1...@thi.ng/defmulti@0.6.0) (2019-01-01)
### Features
* **defmulti:** add addAll(), add/update doc strings ([488698a](https://github.com/thi-ng/umbrella/commit/488698a))
## [0.5.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/defmulti@0.5.0...@thi.ng/defmulti@0.5.1) (2018-12-15)

@@ -8,0 +19,0 @@

51

index.d.ts

@@ -22,7 +22,54 @@ import { IObjectOf } from "@thi.ng/api/api";

export interface MultiFnBase<I> {
add(id: PropertyKey, g: I): boolean;
/**
* Registers implementation for dispatch value `id`. Returns true,
* if successful. Returns false if an implementation already exists
* (and does nothing in this case).
*
* @param id
* @param impl
*/
add(id: PropertyKey, impl: I): boolean;
/**
* Takes an object of dispatch values and their implementations and
* calls `.add()` for each KV pair. Returns true, if all impls were
* added successfully. Note: Only numbers or strings are accepted as
* dispatch values here.
*
* @param impls
*/
addAll(impls: IObjectOf<I>): boolean;
/**
* Removes implementation for dispatch value `id`. Returns true, if
* successful.
*
* @param id
*/
remove(id: PropertyKey): boolean;
isa(id: PropertyKey, parent: PropertyKey): any;
/**
* Updates dispatch hierarchy by declaring dispatch value `id` to
* delegate to `parent`'s implementation. I.e. in terms of dispatch
* logic, `id` is considered the same as `parent.
*
* @param id
* @param parent
*/
isa(id: PropertyKey, parent: PropertyKey): boolean;
/**
* Returns all known dispatch relationships. This is an object with
* all registered dispatch values as keys, each with a set of parent
* dispatch values.
*/
rels(): IObjectOf<Set<PropertyKey>>;
/**
* Returns a set of immediate parent dispatch values for given
* dispatch value `id`.
*
* @param id
*/
parents(id: PropertyKey): Set<PropertyKey>;
/**
* Similar to `parents()`, but includes all transitive parent dispatch
* values for given dispatch value `id`.
* @param id
*/
ancestors(id: PropertyKey): Set<PropertyKey>;

@@ -29,0 +76,0 @@ }

13

index.js

@@ -7,5 +7,5 @@ "use strict";

function defmulti(f, ancestors) {
let impls = {};
let rels = ancestors ? makeRels(ancestors) : {};
let fn = (...args) => {
const impls = {};
const rels = ancestors ? makeRels(ancestors) : {};
const fn = (...args) => {
const id = f(...args);

@@ -21,2 +21,9 @@ const g = impls[id] || findImpl(impls, rels, id) || impls[exports.DEFAULT];

};
fn.addAll = (_impls) => {
let ok = true;
for (let id in _impls) {
ok = fn.add(id, _impls[id]) && ok;
}
return ok;
};
fn.remove = (id) => {

@@ -23,0 +30,0 @@ if (!impls[id])

{
"name": "@thi.ng/defmulti",
"version": "0.5.1",
"version": "0.6.0",
"description": "Dynamically extensible multiple dispatch via user supplied dispatch function.",

@@ -41,3 +41,3 @@ "main": "./index.js",

},
"gitHead": "159ce8f6b1d2dad1e12f2ba3f4f7b60d1623acee"
"gitHead": "7729d993a27cc0cc69cb076c1070ad4e8eccd06a"
}
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