GithubHelp home page GithubHelp logo

Comments (10)

mikke123 avatar mikke123 commented on September 25, 2024

I've found javascript variable:

search_order: [
  // TODO: air
  'localstorage',
  'globalstorage', 
  'gears',
  'cookie',
  'ie',
  'flash'
],

I need to use Flash, however - Flash support is BROKEN in this version of PersistJS, because of race condition (#942):

        // create new swf object
        swfobject.embedSWF(this.o.swf_path || cfg.path, cfg.id, cfg.size.w, cfg.size.h, '8', null, {}, cfg.params, {}, function(o) {
          // save flash element
          B.flash.el = o;
        });
      }

      // use singleton flash element
      this.el = B.flash.el;

B.flash.el is set async meaning that this.el = B.flash.el; gets execute before. It seems that version from http://pablotron.org/?cid=1557 works fine with Flash so I'll see if I can use that one. By the way - which one version is newer? Can we combine them somehow?

from persist-js.

jeremydurham avatar jeremydurham commented on September 25, 2024

Please test the latest version. The object was incorrectly set to the swfobject callback instead of the element.

from persist-js.

mikke123 avatar mikke123 commented on September 25, 2024

Nah, it's not working. I've looked into change you've made and I don't think it's possible to attach el to this like that:

        // create new swf object
        swfobject.embedSWF(this.o.swf_path || cfg.path, cfg.id, cfg.size.w, cfg.size.h, '8', null, {}, cfg.params, {}, function(o) {
          // save flash element
          B.flash.el = o.ref;
          this.el = o.ref;
        });

Correct me if I'm wrong, but I think this is what is needed:

        var self = this;
        // create new swf object
        swfobject.embedSWF(this.o.swf_path || cfg.path, cfg.id, cfg.size.w, cfg.size.h, '8', null, {}, cfg.params, {}, function(o) {
          // save flash element
          B.flash.el = o.ref;
          self.el = o.ref;
        });

It seems that does the trick... dunno why initially I had trouble with get method. Did persist.swf changed from initial version (0.1.0)? This thing hosted on GitHub is newer (0.2.0)??

from persist-js.

mikke123 avatar mikke123 commented on September 25, 2024

And one more question - related to swfobject.js - is it somehow possible to embed that swf synchronously (as it was done in 0.1.0) rather than asynchronously... since this way following will fail:

    var _store;
    $(function() {
        _store = new Persist.Store('test2', {
            swf_path: 'Scripts/persists2/persist.swf'
        });

        var val = _store.get('pbd'); // flash store not yet initialized
    });

from persist-js.

jeremydurham avatar jeremydurham commented on September 25, 2024

Sorry about that, I pushed too hastily last night. I've tested the latest update in Chrome, Safari, Firefox, IE6/7/8 as working. Any luck with the latest version?

from persist-js.

jeremydurham avatar jeremydurham commented on September 25, 2024

Your point about doing it synchronously rather than asynchronously is a good one. I don't personally use the flash backend, ever, but we could probably change the code to:

    // create new swf object
    swfobject.embedSWF(this.o.swf_path || cfg.path, cfg.id, cfg.size.w, cfg.size.h, '8', null, {}, cfg.params, {});
  }

this.el = document[C.flash.id];
},

What do you think?

from persist-js.

mikke123 avatar mikke123 commented on September 25, 2024

Well, I must say I enjoy this conversation - it's nice to work with js pro ;)

And sorry for bothering you, but the reason why I want to force Flash usage is is because it persists between browsers - which is awesome.

Now, as for your change - I've tried number of methods and all of them failed.

  1. this.el = document[C.flash.id] won't work (this.el is null when called in get method)
  2. I've even tried modifying swfobject.js, but if I make that method sync (rather than async & embedding on DomLoad) - any call to Flash throws: Error calling method on NPObject!

So - I dunno what to do. Correction we did (var self and all that) will work for most cases - but when somebody wants to use library on page load (which happens in 90% of cases) the only way it'll work is with setTimeout after init. And as anyone will probably guess - that sucks (I've had tons of troubles with Safari on Mac during yesterday's testing - even with setTimeout(code, 1000) sometimes it works, sometimes it doesn't)

from persist-js.

mikke123 avatar mikke123 commented on September 25, 2024

OK - I've found out why it doesn't work in Safari - if tab is not focused, this.el.get is not function - it is undefined. But when you switch to tab - this.el.get for some reason gets defined as function and starts working.

Anyone has some suggestion for this problem? Because these race conditions really suck.

from persist-js.

jeremydurham avatar jeremydurham commented on September 25, 2024

I've went back and tested Persist 0.1.0, and this issue has existed since at least then.

I also embedded the generated flash into the page, instead of dynamically loading it, and updated persist to use the preloaded embedded flash, but the issue still exists.

I pushed a change to use createSWF instead of embedSWF, which seems to at least help with this.el being undefined. Please try the latest update and tell me if things are any better.

If you would like to upload a zip to reproduce your issue, and I will do my best to help continue debugging it.

from persist-js.

mikke123 avatar mikke123 commented on September 25, 2024

Sorry that I haven't followed up on this; for the sake of those who come over this page in future I just wanted to say that nothing can be done about this issue as it is tied to Safari and how it interacts with Flash.

Simply - if tab is not focused, this.el will be null and that's it. In all other browsers there is no problem with this.

Also, during past 3 months I've been testing persist-js in production on number of websites I administrate and it works really nice. And thanks for that bugfix on async asignment to jeremydurham - that fix was needed.

from persist-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.