Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Event creates data copy in Javascript for every event #40

Closed
Dandandan opened this Issue · 3 comments

3 participants

@Dandandan

I am using this kind of pattern:

changed(object)
{
    //do something with it
}

page() {
   bigobject = /BigObject //I want to only have 1 copy of this in JS
   <input id="1" onchange={function (_) {changed(bigobject)}} value="some text" />
   <input id="2" onchange={function (_) {changed(bigobject)}} value="some text" />
   <input id="3" onchange={function (_) {changed(bigobject)}} value="some text" />
   <input id="4" onchange={function (_) {changed(bigobject)}} value="some text" />
   <input id="5"onchange={function (_) {changed(bigobject)}} value="some text" />
   <input id="6" onchange={function (_) {changed(bigobject)}} value="some text" />
}

This code creates atm this kind of code in the page:

$('#1').opachbind('change', (function(event){(_p)(/*OPA2JS*/ {bigobject)}))
$('#2').opachbind('change', (function(event){(_p)(/*OPA2JS*/ {bigobject)}))
$('#3').opachbind('change', (function(event){(_p)(/*OPA2JS*/ {bigobject)}))
$('#4').opachbind('change', (function(event){(_p)(/*OPA2JS*/ {bigobject)}))
$('#5').opachbind('change', (function(event){(_p)(/*OPA2JS*/ {bigobject)}))
$('#6').opachbind('change', (function(event){(_p)(/*OPA2JS*/ {bigobject)}))

The problem for me is, the info about the controls is in bigobject itself, so my page grows O(n^2) with n controls ;).

@Dandandan

I allso tried this:

   f = function (_) {changed(interface)}

   bigobject = /BigObject //I want to only have 1 copy of this in JS
   <input id="1" onchange={f} value="some text" />
   <input id="2" onchange={f} value="some text" />
   <input id="3" onchange={f} value="some text" />
   <input id="4" onchange={f} value="some text" />
   <input id="5"onchange={f} value="some text" />
   <input id="6" onchange={f} value="some text" />

but that causes a ping (and I don't want that).

@OpaOnWindowsNow

Ok, the big object is constructed dynamically when you create the webpage on server side.
And it is used by all event handler, so it is passed dynamically to all handler.

The perfect solution would be to detect at runtime that we are passing the same object many times and add this optimisation to the opa runtime.
Doing it the sharing at compilation would be too fragile (break on code refactoring ...).

We will think of it.

For now, the workaround solution is too:
-transfer the big object only when you need it (read the big object inside the event handler and not on server)

or

-transfer it to an onready, and store it somewhere on client side (a reference for instance)
use the store in all event handler.

@Dandandan

Ok, thanks!

@akoprow akoprow closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.