Skip to content

Instantly share code, notes, and snippets.

@btakita btakita/agent-example.js
Last active Feb 24, 2018

Embed
What would you like to do?
agent__xyz(ctx).on('change', (ctx) => {
const {x,y,z} = ctx
})
agent__a(ctx).set({a:1})
function agent__xyz(ctx) {
let agent = ctx.agent__xyz
if (agent) return agent
return ensure__agent(ctx, {
key: 'agent__xyz',
scope: ['x', 'y', 'z'],
init() {
agent = this
agent__a(ctx).on('change', agent.reset)
},
async reset() {
const {a} = ctx
, everything = await everything__async()
, z = a + 1 + everything
, y = z + 1 + everything
, x = y + 1 + everything
agent.set({x, y, z})
}
})
async function everything__async() {
return 42
}
}
function agent__xyz(ctx) {
let agent = ctx.agent__xyz
if (agent) return agent
return ensure__agent(ctx, {
key: 'agent__a',
scope: ['a']
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.