Comparing version 0.0.21 to 0.0.22
@@ -108,9 +108,23 @@ 'use strict' | ||
} | ||
const Task = (id, params = {}) => | ||
const NoLog = () => {} | ||
const Task = (id, params = {}, description = Description()) => | ||
Object.assign( | ||
({ actor, perspective }) => | ||
actor.attemptsTo(perspective.handlerFor({ id, params })), | ||
({ actor, perspective, log = NoLog }) => { | ||
log(description.toString()) | ||
return actor.attemptsTo(perspective.handlerFor({ id, params })) | ||
}, | ||
{ id } | ||
) | ||
const Interaction = (fn, description) => ({ | ||
actor, | ||
log = NoLog, | ||
...abilities | ||
}) => { | ||
log(description.toString()) | ||
return fn({ actor, log, ...abilities }) | ||
} | ||
module.exports = { | ||
@@ -120,4 +134,5 @@ Actor, | ||
Task, | ||
Interaction, | ||
Description, | ||
Id, | ||
} |
@@ -5,3 +5,3 @@ 'use strict' | ||
const sinon = require('sinon') | ||
const { Perspective, Actor, Task } = require('./core') | ||
const { Perspective, Actor, Task, Description, Interaction } = require('./core') | ||
@@ -146,2 +146,21 @@ describe('feynman core objects', () => { | ||
}) | ||
describe('logging', () => { | ||
it('logs when a task is attempted', async () => { | ||
const log = sinon.spy() | ||
const doSomething = Task('doSomething', {}, Description('Do something!')) | ||
const perspective = Perspective('Perspective', handle => { | ||
handle({ id: 'doSomething' }, () => () => {}) | ||
}) | ||
await Actor({ log }, perspective).attemptsTo(doSomething) | ||
sinon.assert.calledWith(log, 'Do something!') | ||
}) | ||
it('logs when an interaction is attempted', async () => { | ||
const log = sinon.spy() | ||
const doSomething = Interaction(() => {}, Description('Do something!')) | ||
await Actor({ log }, Perspective()).attemptsTo(doSomething) | ||
sinon.assert.calledWith(log, 'Do something!') | ||
}) | ||
}) | ||
}) |
'use strict' | ||
const { Description, Id, Task } = require('./core') | ||
const { Description, Id, Task, Interaction } = require('./core') | ||
const Interaction = (fn, description = Description()) => { | ||
const DefineInteraction = (fn, description = Description()) => { | ||
if (typeof fn !== 'function') throw new Error('An action must be a function') | ||
const handler = (...args) => fn(...args) | ||
return Object.assign(handler, { | ||
return Object.assign(Interaction(fn, description), { | ||
description, | ||
withContext: ({ description }) => Interaction(fn, description), | ||
withContext: ({ description }) => DefineInteraction(fn, description), | ||
}) | ||
@@ -16,3 +15,3 @@ } | ||
return Object.assign( | ||
Task(context.id, context.params), | ||
Task(context.id, context.params, context.description), | ||
{ | ||
@@ -80,3 +79,3 @@ withContext: context => DefineTask(definition, context), | ||
task: (paramName, subTasks) => MakeTask(paramName, subTasks), | ||
action: Interaction, | ||
action: DefineInteraction, | ||
} |
{ | ||
"name": "feynman", | ||
"version": "0.0.21", | ||
"version": "0.0.22", | ||
"description": "A screenplay pattern library for javascript", | ||
@@ -5,0 +5,0 @@ "main": "lib/feynman.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
820
0
32335308