FDC3 / API

Open standards for the financial desktop.
https://fdc3.finos.org
Apache License 2.0
9 stars 9 forks source link

Suggestion: Intents should not be stateful objects. #12

Closed ColinEberhardt closed 6 years ago

ColinEberhardt commented 6 years ago

Currently intents are used as follows:

// how we locate the agent is platform specific - assuming it is a global in this example!
const agent = fdc3;

const context = {};
const intent = agent.intent("intent", context);

// at this point you can mutate the various properties
intent.target = "foo";

// when sending you can also change the context and target!
const result = await intent.send({foo: "bar"}, "MyApp")

// do something with the result
console.log(result);

// what state is the intent object in here? can I send again?

The above code snippet highlights quite a few ambiguities.

I'd propose a simpler API, that removes the Intent object altogether:

const agent = fdc3;

const context = {};
const intent = "DoSomething"
const result = await agent.sendIntent(intent, context);
console.log(result);

Much simpler!

rikoe commented 6 years ago

I couldn't agree more with this, and I am disappointed that this has not been discussed more.

I think for intents to be adopted successfully, the API needs to be really simple, and const result = await agent.sendIntent("StartCall", context); is simple and easy to understand without any ambiguities.

Stateful objects are unnecessary here, and makes for more complicated code to write.

nkolba commented 6 years ago

Completely agree with removing the Intent object and replacing with the sendIntent method.

Let's make the change.

lauchlan commented 6 years ago

Agree with Colin!

rikoe commented 6 years ago

@ColinEberhardt We can close this now after #26, I don't have the ability to.

ColinEberhardt commented 6 years ago

Great, thanks