-
Notifications
You must be signed in to change notification settings - Fork 1k
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
chore(cli): Add functionality class to plugin template #3315
Conversation
Added ios implementation too I made the class public, do we want it public or open (open is like public, but can be overwritten) |
Since we don't have a way to override the functionality class in Android yet, I think we can keep the iOS functionality class just public for now, not open. Allowing access from Objective-C is fine, unless there's a side effect I'm not aware of. @ikeith thoughts on the above? |
A few thoughts:
I'm not a big fan of the use of 'Functionality' in this context because that sounds ambiguous to me. It sounds like it might be just helper functions. Ideally, the relationship would be Also, would it be worth it to make the template more complicated? I imagine that the most likely point that this separation will break down is when needing to handle an async operation. So providing an example of a completion handler could reduce the risk that authors will just pass the plugin call to the second class and defeat the purpose of the wrapper. |
The issue is we refer to it as the "plugin class" everywhere, even though it's just an adapter or wrapper. I was hard pressed to come up with a better suffix than Yes, my idea for a more complicated plugin template was to have a squaring plugin. Give it a number, and it returns the square of that number. If you have ideas for an async example, I'm all ears. |
What about a very simple network operation? Just make an http request to return success or failure? |
How about a plugin that returns the "current working directory" of an app? It would just return the app's root directory on the device. |
IMO the naming should be without a suffix. The Plugin class should have e.g. it's definitely understandable if this architecture is documented (with code comments). Maybe we should add a default code comment in the template? e.g:
|
The problem with using Dan, I think Ian means that it would be more useful to have an async function instead of a more complex sync function, since calling a sync function is easier. But maybe we can have both. But at the moment I can't think of a simple native API we could use. Also, we need to have in mind that the docs have a plugin guide based on the old code and we will need to rewrite it entirely as we are changing the whole template. |
We could update the annotation to accept a name for the JS plugin. I really like @BorntraegerMarc's suggestion. @jcesarmobile We'll need to start a 3.x branch in the Capacitor site shortly. I'm hoping to do that as soon as things settle down with the rewrite/guides being added/etc. |
If we can update the Android annotation to support a different JS name over the class name, then I second the Foo/FooPlugin naming. The iOS code can already support multiple names: the swift class name and the Obj-C class name and the JS name, none of which have to be identical. As for the sample code, having a simple sync call along with an async call would be but great but I can't think of any native API other than network requests which are inherently asynchronous and make sense cross-platform. If we can't come up with an idea to include in the code, we could just provide an example of a network call in the documentation (assuming anyone reads it). |
Okay, I pushed the proposed changes. @jcesarmobile @ikeith @BorntraegerMarc |
FRAMEWORK_SEARCH_PATHS = ( | ||
"\"${BUILT_PRODUCTS_DIR}/Capacitor\"", | ||
"\"${BUILT_PRODUCTS_DIR}/CapacitorCordova\"", | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this needed?
Both are dependencies in the Podfile, so should be able to find them without this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @ikeith was getting it to build without cocoapods?
Shouldn't iOS tests test the implementation class instead of the plugin class? |
Co-authored-by: jcesarmobile <[email protected]>
Co-authored-by: jcesarmobile <[email protected]>
No description provided.