Bug in AjaxSource commit status check

Hey Enyo Folks,
I'm pretty sure I've fully described a bug that I think has been touched on in several posts over the years. Over at http://forums.enyojs.com/discussion/2615/how-to-force-post-on-collection-commit
I describe a fresh client-side collection assembled from
Collection.add(new TaskModel({collectionId: i, description: 'desc' + i, name: ...});
always forcing a PUT because by the time the Collection hits
opts.method = (model.status & States.NEW) ? 'POST': 'PUT'; (Source)
model.status has already moved from "-2041" to "32" ("COMMITTING").
Forcing 'PUT' when the verb should be 'POST'.


  • Forgot to copy the fiddle over from the other thread:
    Run with console open, I don't think it matters that test URL doesn't support CORS, the attempt is clearly PUT.
  • I see a couple of options to fix this:

    A: Make AjaxSource take care of updating the Model or Collection's status after it lands in commit and after it runs it's check to determine POST or PUT.

    B: Have Model and Collection pass options.nextStatus to AjaxSource which applies it after it runs it's check to determine POST or PUT.

    I don't grok a lot of this State bit flipping, or the whole wiring/architecture of status, so I felt more comfortable taking a stab at option "B". It seems closer to the original intent.

    I have a POC fork that modifies AjaxSource.js, Collection.js and Model.js along the lines of option "B" here: https://github.com/bbito/enyo/tree/bbito-commit-next-status

    I'd love some feedback!
  • Okay, as is often the case when I present options A or B, it turns out C is probably a better idea...
    Option C is much less impactful:
    In Model.commit and Collection.commit save the entry status to options.preCommitStatus, leaving other code untouched in those methods.
    In AjaxSource.commit: fallback to previous behavior if options.preCommitStatus === undefined
    However, if that test for undefined fails, set opts.method based on options.preCommitStatus instead of model.status.
    Finally, set options.preCommitStatus = undefined before exiting AjaxSource.commit so it doesn't come back to bite us.
    The new branch for this is: https://github.com/bbito/enyo/tree/bbito-save-pre-commit-status

    I'd like to make a PR for this one, as I'm pretty sure it doesn't break any of the stuff I don't fully understand.
  • https://github.com/bbito/enyo/tree/bbito-save-pre-commit-status
    Updated with cleaner code to check
    if (options.preCommitStatus)
    if (options.preCommitStatus === undefined)

    I'll leave this branch alone for now unless I need a bug fix. I'll do further digging into other issues I'm seeing with Model.status and Collection.status in other branches so this is not affected.

    See github issue: https://github.com/bbito/enyo/issues/2

    I wish I were joining in the "Next Gen" fun, but I can't imagine it will run on my legacy webOS (2.2.4 / 3.0.5) targets...
Sign In or Register to comment.