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

Revisit forcing to-string conversion for can-maps #125

Open
justinbmeyer opened this issue Nov 11, 2017 · 1 comment
Open

Revisit forcing to-string conversion for can-maps #125

justinbmeyer opened this issue Nov 11, 2017 · 1 comment

Comments

@justinbmeyer
Copy link
Contributor

Fixing this:

is just plain weird.

Instead of doing this, I think we should take the serialized data, param it, deparam it. If it doesn't match the original serialized data ... we should warn the user what is going on .

This means people won't be able to set numbers and such (without a type converter), but it will eliminate the zaniness that is going on in 3.0 and would carry onto 4.0.

var stringCoercingMapDecorator = function(map) {
	var sym = canSymbol.for("can.route.stringCoercingMapDecorator");
	if(!map.attr[sym]) {
		var attrSuper = map.attr;

		map.attr = function(prop, val) {
			var serializable = this.define === undefined || this.define[prop] === undefined || !!this.define[prop].serialize,
				args;

			if (serializable) { // if setting non-str non-num attr
				args = stringify(Array.apply(null, arguments));
			} else {
				args = arguments;
			}

			return attrSuper.apply(this, args);
		};
		canReflect.setKeyValue(map.attr, sym, true);
	}

	return map;
};
@justinbmeyer
Copy link
Contributor Author

To be clear ... every time we are going to update the url from route.data changes, I propose that in development mode we do something like:

var serialized = route.data.serialize();
var serializedFromRoute = route.deparam( route.param( serialized) );
if( ! deepEqual(serialized, serializedFromRoute) ) {
  // give a warning about what is different
}

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

1 participant