Skip to content

InputCallback #1

@g105b

Description

@g105b

I'm fleshing out the syntax for a more encapsulated user input model. Taking the "do" terminology from Gt v2, as it is short, fun and friendly.

This interaction model enforces encapsulation, meaning the developer writing the go function must decide which areas of code receive user input, making it impossible for third party libraries to eavesdrop.

Hello, you:

<h1>Hello, <span id="output">you</span>!</h1>

<form>
	<input name="name" required placeholder="Your name" />
	<button name="do" value="submit">Submit!</button>
</form>
public function go() {
// Somewhere to output the variable:
	$outputTo = $this->document->getElementById("output");

// Trigger when "do=submit" is passed.
	$this->input->do("submit")
// List the parameters to pass to the callback.
		->with("name")
// Reference the callback, with optional added properties
		->call([$this, "outputName"], $outputTo);

protected function outputName(InputFields $fields, Node $outputTo) {
//	...
}

Credit card payment:

<form method="post">
	<input name="name" required />
	<input name="postcode" required />
	<input name="creditcard" required />
	<button name="do" value="pay">Pay me your money</button>
</form>
public function go() {
	$this->input->do("pay")
// All fields need passing to payment processor:
		->withAll()
		->call([Payment::class, "process"])
// ...but the user storage should not see credit card information.
		->without("creditcard")
		->call([User::class, "storeDetails"]);
}

A short syntax for developers who don't need extra features:

public function go() {
	$this->input->do("something")->callWithAll(function(InputFields $fields) {
		foreach($fields as $field) {
			someAction($field);
		}

		somethingElse($fields->fieldName);
	});
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions