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

@tangle/strategy

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tangle/strategy

a toolkit for composing tangle reducing strategies


Version published
Weekly downloads
165
increased by511.11%
Maintainers
2
Weekly downloads
 
Created
Source

@tangle/strategy

A strategy is a way of describing "transformations" and how to apply them to one another

A valid strategy is an Object which provides the following:

  • identity Function - an getter which return an element which represents the identity-transformation.
  • isValid Function - takes a transformation and tells you whether it is a valid for this strategy
  • concat Function - takes two transformations (a, b) and concatenates (applies) b to a. Note order matters
  • reify Function - takes a transformation and maps it into a "real" state which can be used in e.g. human interfaces
  • ... more to follow

This module allows you compose larger strategies for transformations made up of transformations

Example Usage

const Strategy = require('@tangle/strategy')

const strategy = new Strategy({
  title: require('@tangle/overwrite')(),
  attendees: require('@tangle/simple-set')()
})

const T1 = {
  title: { set: 'brunch' },
  attendees: { mix: 1, alanna: 1 }
}
const T2 = {
  title: { set: 'Brunch at Mixs' },
  attendees: { alanna: -1, ben: 1 }
}

const T3 = strategy.concat(T1, T2)
// => {
//  title: { set: 'Brunch at Mixs' },
//  attendees: { mix: 1, ben: 1 }
// }

strategy.reify(T3)
// => {
//  title: 'Brunch at Mixs',
//  attendees: ['ben', 'mix']
// }

API

Strategy Requirements

Rules for how a strategy must behave:

  • have a unique identity element
    concat(identity(), a) === a
    concat(a, identity()) === a
    
  • be associative
    concat(concat(a, b), c) === concat(a, concat(b, c))
    

An identity element is important because we need to be able to clearly communicate "I don't want to perform a change"

Associativity is important because in scuttlebutt we may have many contributions from different people across time, and being able to group chunks of transformations in a free-form way greatly increases our flexibility. (e.g. it allows us to summarise a bunch of transformations and save that. this is something useful for writing merge messages)

p.s. a Set which has an associative concat and an identity element is called a "monoid"

BONUS:

  • if your strategy is commutative, merging gets REALLY easy
    concat(a, b) === concat(b, a)
    

Keywords

FAQs

Package last updated on 13 Oct 2020

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