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

feynman

Package Overview
Dependencies
Maintainers
4
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

feynman - npm Package Compare versions

Comparing version 0.0.15 to 0.0.16

lib/feynman/core.js

144

lib/feynman.js
'use strict'
/*
* Actor - attempts actions using its abilities, it knows how to perfom
* actions in its context
* Ability - dependencies that the interaction needs to do its work
* example: browser, the domain api
* options: capability, tool, faculty, dependency
* Perspective - a group of Interactions that use a particular set of Abilities
* Action - is a general term for task or interaction
* Task - tasks are composed of tasks or interactions
* Interaction - directly uses abilities to do something to the app
*/
/*
* Annoyances
*
* - there's two if statements
*/
const Actor = (abilities = {}, perspective = Perspective('unknown')) => {
const actor = {
attemptsTo: async (...actions) => {
for (const action of actions) {
const handler = perspective.handlerFor(action)
await handler({ actor, ...abilities })
}
return actor
},
asks: async question => {
const handler = perspective.handlerFor(question)
return handler({ actor, ...abilities })
},
through: newPerspective => Actor(abilities, newPerspective),
gainsAbilities: extraAbilities => {
Object.assign(abilities, extraAbilities)
return actor
},
perspective,
}
return actor
}
const Task = (id, description, args, fn) => {
const nestedTasks = []
const task = (..._params) => {
const params = _params.reduce(
(params, param, index) => ({ [args[index]]: param, ...params }),
{}
)
const action = {
id,
params,
}
nestedTasks.forEach(NestedTask => {
const nestedTaskName = NestedTask.id.split('.').pop()
action[nestedTaskName] = (...args) => {
const nestedAction = NestedTask(...args)
nestedAction.params = { ...action.params, ...nestedAction.params }
return nestedAction
}
action[nestedTaskName].id = NestedTask.id
action[nestedTaskName].description = NestedTask.description
})
return action
}
task.id = id
task.description = description
if (fn)
fn((id, description, _args, fn) => {
const NestedTask = Task(
`${task.id}.${id}`,
`${task.description} ${description}`,
{ ...args, ..._args },
fn
)
task[id] = NestedTask
nestedTasks.push(NestedTask)
})
return task
}
const Perspective = (name, definition) => {
const handlers = {}
const perspective = {
handlerFor: action => {
if (!action.hasOwnProperty('id')) return action
const { id, params = {} } = action
if (!handlers.hasOwnProperty(id))
throw new Error(
`No handler found for task "${
action.id
}" in "${name}" perspective.\n\nAlternatives:\n${Object.keys(
handlers
).join('\n')}`
)
return handlers[id](params)
},
name: name,
}
const registerHandler = (action, fn) => {
handlers[action.id] = fn
}
if (definition) definition(registerHandler)
return perspective
}
const Remember = {
that: item => ({
is: value => ({ remember }) => remember(item, value),
}),
}
const Recall = {
about: item => ({ recall }) => recall(item),
}
const Memory = () => {
const state = new Map()
return {
remember(item, value) {
state.set(item, value)
},
recall(item) {
if (!state.has(item))
throw new Error(
`I do not remember anything about '${item}', sorry.\n\nHere's what I *do* know about:\n${Array.from(
state.keys()
)
.map(name => `- ${name}`)
.join('\n')}\n\nWhy not ask me about those things instead?`
)
return state.get(item)
},
}
}
module.exports = {
Actor,
Memory,
Perspective,
Remember,
Recall,
Task,
...require('./feynman/core'),
...require('./feynman/dsl'),
}
{
"name": "feynman",
"version": "0.0.15",
"version": "0.0.16",
"description": "A screenplay pattern library for javascript",

@@ -26,4 +26,6 @@ "main": "lib/feynman.js",

"prettier": {
"semi": false
"semi": false,
"trailingComma": "es5",
"singleQuote": true
}
}

Sorry, the diff of this file is not supported yet

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