Make private View methods private

RESOLVED WONTFIX

Status

Firefox OS
Gaia::L10n
RESOLVED WONTFIX
3 years ago
4 months ago

People

(Reporter: stas, Assigned: stas)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments)

(Assignee)

Description

3 years ago
View methods like observe, disconnect and _resolveEntity should only be accessible by priviledged code, in this case, the DOM bindings.

We can achieve this using Symbols.  I have a PoC ready which I can finish and rebase after bug 1204086, bug 1207120 and bug 1207121 land.
(Assignee)

Comment 1

3 years ago
Created attachment 8664184 [details] [diff] [review]
PoC

https://github.com/stasm/l20n.js/tree/1207122-private-view-methods
Assignee: nobody → stas
Status: NEW → ASSIGNED
Attachment #8664184 - Flags: feedback?(gandalf)
(Assignee)

Comment 2

3 years ago
We can use the same approach to hide view.doc and others.

It all boils down to defining "interfaces" or "protocols".  The DOM bindings might define a PDom protocol, while the View can define its own PView protocol with symbols which will be used to access private methods and properties.

(In the PR I used the name IView instead of PDom.)
Uuuh, I have to say that it feels to me like obfuscating the code. I'll look more into this, but I'm wondering if if we can just define them as local functions instead of using Symbols?
(Assignee)

Comment 4

3 years ago
Hmm, I haven't found a way to do this in the setup we have right now.  If 'resolveEntity' is a local function in view.js, you need to import it in dom.js and use it like this:  resolveEntity.call(view, …).  I'd like to be able to do this this way, but as far as I understand it, it makes it impossible to reuse the dom.js code in other bindings, e.g. gaiabuild.  Gaiabuild's View needs to have its own resolveEntity, while with the local function apporach, dom.js hardcodes import { resolveEntity } from 'src/bindings/html/view';

I found that local functions make it generally harder to extend the code.  Symbols, OTOH, can be imported by the code which wants to do the extending.

Do you have other ideas on how to achieve this?  It bugs me that half of View's public methods are in fact private.
(Assignee)

Comment 5

3 years ago
Created attachment 8665663 [details] [review]
Pull request

I updated and clean up the code a bit.  Attaching the link to the pull request so it doesn't get lost.
Comment on attachment 8664184 [details] [diff] [review]
PoC

not a target at the moment.
Attachment #8664184 - Flags: feedback?(gandalf)

Comment 7

4 months ago
Firefox OS is not being worked on
Status: ASSIGNED → RESOLVED
Last Resolved: 4 months ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.