-
-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Definition API -> Builder pattern? #63
Comments
This looks a lot easier to read, doesn't require referring to documentation/IntelliSense to understand the order of parameters. Would the |
Yeah they'd be chainable. Order wouldn't necessarily matter as it'd just add to the middleware array - the calls would just modify the resulting object it uses anyway for the definition (like your typical builder) |
Sounds good to me! |
Alrighty have a loose idea I'm playing around with, but being backwards-compat: TestV4ServerFunction: Net.Definitions.AsyncFunction()
.EnsureArguments<[value: string]>(t.string)
.EnsureReturns(t.string)
.WithRateLimit({
MaxRequestsPerMinute: 10,
})
.WithCallbackMiddleware((procNext, instance) => {
return (player, name) => {
if (someCondition) {
return procNext(player, name);
} else {
return NetMiddleware.Skip;
}
};
})
.ForServer(), Essentially will have I ideally do want to make type checks mandatory but it's less backwards compatible and awkward with the async function. |
const BuilderRemotes = Net.Definitions.Create()
// Create a namespacae using an object model
.AddNamespace("ExampleNamespaceObject", {
ExampleEvent: Net.Definitions.Event().EnsureArguments(t.string).OnServer(), // Event for server taht takes
})
// Create a namespace using another builder + object model
.AddNamespace(
"ExampleNamespaceUsingInnerBuilder",
Net.Definitions.Create().Add({
// Example object-like
ExampleAsyncFunction: Net.Definitions.AsyncFunction().OnClient(),
}),
)
// Create a namespace with a builder functionally
.AddNamespace(
"ExampleNamespaceUsingFunctionalBuilder",
builder => {
// You can add remotes one by one functionally like this
return builder
.AddClientRemote("ClientRemoteName", Net.Definitions.AsyncFunction())
.AddServerRemote("ServerRemoteName", Net.Definitions.Event());
}, // add a client remote using a function
)
// Of course like our inner builder, we can use 'Add' here.
.Add({
ExampleBaseRemote: Net.Definitions.AsyncFunction().OnServer(),
// Can add a created definition as a namespace to an object model
ToNamespaceBehaviour: Net.Definitions.Create().ToNamespace(),
})
.AddServerRemote("NamedBaseServerRemoteFunction", Net.Definitions.AsyncFunction())
.AddClientRemote("NamedBaseClientRemoteEvent", Net.Definitions.Event())
.Build(); I'm also considering |
I feel like the definitions API could be cleaner, perhaps instead of doing something like:
We could do
Could simplify this further for built-in middleware, such as
.WithTypeChecking(...types)
and.WithRateLimit(options)
This could play well with #62.
The text was updated successfully, but these errors were encountered: