Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store.loadRecords - Only save real changes to datahashes #176

Closed
DominikGuzei opened this issue Oct 5, 2011 · 2 comments
Closed

Store.loadRecords - Only save real changes to datahashes #176

DominikGuzei opened this issue Oct 5, 2011 · 2 comments

Comments

@DominikGuzei
Copy link

Hey Sproutcore Team!

I started building my first real project with Sproutcore 2 and I am amazed how nice all the parts fit together!
Still I want to share one thing that I didn't find logical or maybe I would even call it a bug:

For my app I periodically fetch records of different types from the backend to see if properties changed on them. When they arrive at the data source I push the records into the store with loadRecords as suggested. The only problem is that althought most of the records would stay the same (data hashes have same data as before) the loadRecords method invokes dataHashDidChange for each of them. This results in refreshing the complete view layer for each fetch and made it impossible to stay at specific scroll position because since for very short time the (in my case pretty complex) tree was gone and rebuilt.

Even if it wasn't that obvious like in my case -> a short lookup if actually anything changed on the data hash would be far better!?

Please tell me if I totally messed up some concepts, but here is the hacky solution I used for now in my app:

var PatchedStore = SC.Store.extend({

/**
 * @Overrides SC.Store.loadRecord
 *
 * Since original loadRecord method doesnt check if
 * the datahash actually changed this is a monkey patch
 * to introduce this to the store class. Otherwise all
 * bindings would fire and the whole view be rebuild
 * alhought nothing changed on the record.
 */
 loadRecord: function(recordType, loadedHash, id) {
    if(loadedHash || id) {
        var key = this.storeKeyFor(recordType, loadedHash.id ? loadedHash.id : id);
        var existingHash = this.readEditableDataHash(key);

        // not new record -> compare contents
        if(!existingHash || JSON.stringify(loadedHash) != JSON.stringify(existingHash)) {
            this._super(recordType, loadedHash);
        }
    }
 }

});
@wagenet
Copy link
Member

wagenet commented Nov 17, 2011

I think this belongs in the https://github.com/sproutcore/sproutcore-datastore repo.

@wagenet wagenet closed this as completed Nov 17, 2011
@DominikGuzei
Copy link
Author

You are right, I posted it there - thanks!

locks added a commit that referenced this issue Jul 27, 2017
Used RFC #176 modules API for imports.
locks added a commit that referenced this issue Jul 27, 2017
Used RFC #176 modules API for imports.
locks added a commit that referenced this issue Jul 27, 2017
Used RFC #176 modules API for imports.
Also cleaned up some of the globals-mode usage.
locks added a commit that referenced this issue Aug 16, 2017
# This is the 1st commit message:
typo in comment

# The commit message #2 will be skipped:

#	indent yuidoc comment

# The commit message #3 will be skipped:

#	remove IE8 test

# The commit message #4 will be skipped:

#	remove commented out test

# The commit message #5 will be skipped:

#	use file path and add imports
#
#	Used RFC #176 modules API for imports.
#	Also cleaned up some of the globals-mode usage.

# The commit message #6 will be skipped:

#	clean up more globals style documentation

# The commit message #7 will be skipped:

#	Updates blueprints

# The commit message #8 will be skipped:

#	remove extra type check

# The commit message #9 will be skipped:

#	[BUGFIX beta] Reusing element causes problems in Safari
#
#	When testing allowed input types, in some versions of Safari the type
#	cannot be change to `file` if previously set to a different one.
#
#	Fixes #14727

# The commit message #10 will be skipped:

#	[DOC release]missed code block added

# The commit message #1 will be skipped:

#	[DOC release] Update wait.js - Add missing backticks to code snippet.

# The commit message #2 will be skipped:

#	use safe `toString` for array content in `mixins/array`

# The commit message #3 will be skipped:

#	avoid expanding already expanded property key in computed.sort

# The commit message #4 will be skipped:

#	avoid expanding already expanded property key in reduceMacro/arrayMacro/multiArrayMacro

# The commit message #5 will be skipped:

#	[DOC release] Make `Ember.expandProperties` public

# The commit message #6 will be skipped:

#	reuse meta `arrayContentDidChange`

# The commit message #7 will be skipped:

#	replace `throw` with assertion in `enumerable`

# The commit message #8 will be skipped:

#	[BUGFIX beta] Allow boolean values for current-when
#
#	As the docs say, `A link will be active if current-when is true`.
#	Looks like this might have been broken since 1.13 and #12344
#	did not seem to actually fix this particular bug.
#
#	Related issues:
#
#	- #12512
#	- #12630 (fix was not merged)
#	- #12296

# The commit message #9 will be skipped:

#	remove unused imports

# The commit message #10 will be skipped:

#	[DOC] Improve Ember.isEmpty

# The commit message #1 will be skipped:

#	micro optimization in `enumerable`
rwjblue added a commit that referenced this issue Aug 16, 2017
Update blueprints and tests to RFC #176
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants