Closed Bug 1207122 Opened 9 years ago Closed 6 years ago

Make private View methods private

Categories

(Firefox OS Graveyard :: Gaia::L10n, defect)

ARM
Gonk (Firefox OS)
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: stas, Assigned: stas)

References

Details

Attachments

(2 files)

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.
Attached patch PoCSplinter Review
https://github.com/stasm/l20n.js/tree/1207122-private-view-methods
Assignee: nobody → stas
Status: NEW → ASSIGNED
Attachment #8664184 - Flags: feedback?(gandalf)
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?
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.
Attached file 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)
Firefox OS is not being worked on
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: