fs-webcomponents / fs-elements

Collection of FamilySearch Polymer elements.
https://www.webcomponents.org/collection/fs-webcomponents/fs-elements
MIT License
4 stars 0 forks source link

Do we need to change or remove fs-behavior? #16

Closed justincy closed 7 years ago

justincy commented 7 years ago

[Thinking out loud here.]

Now that fs-request has been created and manages interaction with fs-client, the majority of the functionality provided by fs-behavior isn't needed. All that's left is the clientName property.

That leads two a few ideas:

justincy commented 7 years ago

Docs for Polymer class mixins (not to be confused with CSS mixins): https://www.polymer-project.org/2.0/docs/devguide/custom-elements#mixins

justincy commented 7 years ago

More thoughts.

The naive implementation of fs-request would have fs-client in it's shadow DOM. I initially didn't want that because it seemed like a waste of resources to create a shadow root for an element that had no impact on display. However I was forced to follow that route initially because fs-client wouldn't work unless it was attached to the DOM. I tried to modify the behavior of fs-client to use property observers instead of ready() but was surprised to have the same issue. I settled with just manually calling configuration methods on fs-client from fs-request and kept fs-client in memory.

But that is all against the grain of Polymer. Why bother using an element in memory? Why not just use an object? I noticed that google-analytics-loader is a functional display-less element that includes other display-less elements in it's shadow DOM. It's declarative, in line with custom elements ethos, and provides nice encapsulation by guarding the components and internal behavior. So I think I'm sold on using the shadow DOM.

An implication of this is that now I have a usecase for fs-behavior that includes using both the clientName property and the getClient() method which means we may not want to split those as described above.

justincy commented 7 years ago

fs-behavior provides three pieces:

  1. clientName property which allows all fs elements to optionally specify which SDK client will be used.
  2. getClient() method which enables elements to access the SDK client.
  3. isAuthenticated() method which is just a helper for determining whether the SDK client is authenticated.

clientName needs to be exposed on all fs elements that need API access. Perhaps we split that into a behavior (class mixin) called fs-api-enabled or fs-api-aware like google-signin-aware.

getClient() will be used by fs-request and fs-person-behavior but it's so simple that we could just copy it into both.

isAuthenticated() is used by:

justincy commented 7 years ago

I think I've convinced myself that we can kill fs-behavior.