Full vs Shim compatibility
Closed this issue · 3 comments
Hi,
I'm the author of Scene Packer and currently include your shim but not a hard dependency.
I've been asked whether it's possible to remove the popup dialog that's bundled in the shim. I know it's possible, but I want to know what the differences currently are between the full module and the shim version. I can't see an issue or wiki entry that lists the differences and only one issue from several months ago (#3) that discusses differences.
My current thought is to use the shim that you provide, but remove the popup dialog, therefore using the full module if it's enabled but not prompting people if it isn't. What functionality would be lost with this approach though?
I probably should add a much more detailed explanation of the differences between the full library and the shim in the documentation. I'll keep this ticket open until I find time to do it, so I don't forget.
Removing the shim notification
Regarding your question about disabling the warning dialog, as you seem to be aware, yes you can strip the corresponding part of the code (second half of the shim) and no functionality is compromised. It was written knowing some people might not wish for that notification to be there. I am aware of multiple modules that do this, so you wouldn't be the only one.
I.e., you can just strip this entire section (or simply set WARN_FALLBACK
to false
, if you prefer):
Lines 63 to 113 in ba9942f
Difference between shim and full library
With regards to the difference in functionality, in essence the shim does standard javascript wrapping, and nothing else.
-
Shim does not support any user-facing functionality. Think prioritization of modules, conflict detection, list of wrappers, etc. Basically, anything you can access through the libWrapper settings menu.
-
Shim does not support
libWrapper.unregister
/libWrapper.unregister_all
calls. -
Shim does not support dynamic dispatch. The next method in the wrapper chain is calculated at the time of each
register
call, and never changed/reordered later. This has many implications:-
The wrapper type metadata (
WRAPPER
,MIXED
,OVERRIDE
) is completely ignored. The wrapper call order will match the order in which they are registered. For instance, if a module registers anOVERRIDE
after your module, you will never be called. Nobody guaranteesMIXED
wrappers come after allWRAPPER
wrappers, nor thatOVERRIDE
wrappers come after allMIXED
wrappers. -
Inheritance chains are static. If you have
class B extends A
and overrideB.prototype.foo
before someone else overridesA.prototype.foo
, callingB.prototype.foo
will skip theA.prototype.foo
wrapper. -
There is no distinction between a libWrapper (Shim) wrapper and a non-libWrapper wrapper. While normally non-libWrapper wrappers will always come after all libWrapper wrappers, when using the shim this is not the case.
-
-
None of the libWrapper safeties are guaranteed when using the shim. For instance, nothing checks that modules alway call
wrapped(...args)
when usingWRAPPER
. Nothing checks that there can only be oneOVERRIDE
wrapper on a given method. -
There are no libWrapper Hooks when using the shim.
These are probably the most relevant differences. In essence, using the shim does not give you any advantage when it comes to compatibility versus not using libWrapper at all. As soon as two modules wrap the same thing, it is very likely things will break.
The intent of the shim is to remove the disadvantage from using libWrapper, i.e. of tying yourself to a dependency. It means that using libWrapper does not imply being tied to libWrapper, since if you disable libWrapper you get the exact same behaviour you would if you were doing everything by hand. You can take advantage of the benefits of libWrapper, while still working as if libWrapper didn't exist when libWrapper isn't installed.
As a bonus it brings in a few ease-of-use features such as support for getters/setters and inherited methods, but nothing that couldn't be done by hand with a couple of lines of code.
Hopefully this answers your question. Let me know if not, or if you have any more questions.
I have now updated the shim documentation with the above information.
Closing this ticket. Feel free to re-open if the above (or the documentation changes) did not answer all your questions.