Closed Pavel910 closed 4 years ago
@Pavel910 that's an interesting approach! I like that everything is handled by the template as this is where it should be.
Parameters --component are located in the inputs
If that's the case, why is the change https://github.com/serverless/components/pull/509 required? 🤔 ... Aren't all inputs in the first object argument?
@eahefnawy the problem with that PR is not the inputs, but access to component's state.
Once I load the relevant component and run the custom method, I would like to be able to access the current state of the component, but that doesn't really work, because I'm loading component via instance of the Template
, here is the reference, and that triggers your wrapper function which ignores all but the first parameter. That causes the alias
to not be passed in, and the component state doesn't get loaded. So that other PR fixes argument handling.
Thanks @Pavel910 ... that makes sense!
I love how you can now run a single command on multiple components. When I first thought of this, I only considered running a single command on a single component.
The only thing I'm worried about is that we haven't really defined the components CLI as a whole. (what commands & options..etc). So may need to set this install
or --component
command/option as reserved if we need to. But for now, it's super flexible.
LG2M! 🎉
This PR attempts to solve the problem discussed in issue #497.
This is my take on the problem, @eahefnawy please see the explanation below and let me know if you have a different idea about the implementation:
Solution
Everything is handled by the
Template
component, so fromcli
perspective nothing is changed. The cool part is, whencli
checks if the component has a custom method, and the component happens to be an instance ofTemplate
, theProxy
will return a "proxy" function to execute custom methods . Parameters--component
are located in theinputs
, so we can easily treat them equally from both CLI and programmatic perspective.Below is the example invocation and the resulting output:
Let me know what you think and if any changes are required 🍻