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

Reference properties #1774

Merged
merged 28 commits into from
Jun 5, 2014
Merged

Reference properties #1774

merged 28 commits into from
Jun 5, 2014

Conversation

mramato
Copy link
Contributor

@mramato mramato commented Jun 2, 2014

This refactors the existing ReferenceProperty implementation to fix a plethora of issues it had and make it more useful overall. It also extends CZML capabilities for working with references, as discussed in AnalyticalGraphicsInc/czml-writer#66

  1. You can now reference sub-properties, not just top-level properties.
  2. It properly raises definition changed event (it previously did not).
  3. It now throws if a reference property is invalid, which is better in practice than silently returning undefined, as it did previously.
  4. CZML now lets you reference any leaf property from any other leaf property. i.e. To objects can share the same position property.
  5. CZML can now reference "local" properties, i.e. billboad.scale can reference model.scale on the same object in order to keep them in sync and send less data.

CzmlDataSource.js is a little unwieldy, but I'm hoping to do a major clean up of the code for 1.0. Hopefully it's not too hard to review the changes currently needed for the above.

@mramato mramato mentioned this pull request Jun 5, 2014
70 tasks
@@ -1724,6 +1761,7 @@ define([
* @param {Object} packetData The CZML packet being processed.y
* @param {TimeInterval} [interval] A constraining interval for which the data is valid.
* @param {String} [sourceUri] The originating uri of the data being processed.
* @param {DynamicObjectCollection} [dynamicObjectCollection] The collection being processsed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parameter is not really optional, is it? It will crash if you don't provide it and you process a packet with a reference in it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of the ones marked optional are actually optional I think. I'll change the doc. This entire file is due for a major cleanup, overhaul before we hit 1.0; I will probably do it as part of the "automatically process custom properties" changes.

@mramato
Copy link
Contributor Author

mramato commented Jun 5, 2014

Your current set of comments have all been addressed.

return -1;
}

function trySplit(value, delimiter) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like it would be a lot simpler to just walk the reference string, start to finish, and parse as you go, keeping state variables to detect escape sequences. You really don't need to pre-determine all the indices up front.

basically (this is concise enough to just go in fromString)

        var identifier;
        var values = [];

        var inIdentifier = true;
        var isEscaped = false;
        var token = '';
        for (var i = 0; i < referenceString.length; ++i) {
            var c = referenceString.charAt(i);

            if (isEscaped) {
                token += c;
                isEscaped = false;
            } else if (c === '\\') {
                isEscaped = true;
            } else if (inIdentifier && c === '#') {
                identifier = token;
                inIdentifier = false;
                token = '';
            } else if (!inIdentifier && c === '.') {
                values.push(token);
                token = '';
            } else {
                token += c;
            }
        }
        values.push(token);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a huge mental block when writing this code, so thanks for this. I agree this is much cleaner.

* Creates a new instance given the dynamic object collection that will
* be used to resolve it and a string indicating the target object id and property.
* The format of the string is "objectId#foo.bar", where # separates the id from
* property path and . separates sub-properties.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably document how to escape # and . and \ in the documentation here too.


//>>includeStart('debug', pragmas.debug);
if (parts.length !== 2) {
throw new DeveloperError('referenceString must contain a single . delineating the target object ID and property name.');
if (identifier === '' || values.length === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these checks would be appropriate to move to the constructor instead, since they apply just as well there.

@mramato
Copy link
Contributor Author

mramato commented Jun 5, 2014

All good stuff, I added a couple of extra specs to cover the extra checks being done in the constructor as well. Ready to go.

shunter added a commit that referenced this pull request Jun 5, 2014
@shunter shunter merged commit 76317d6 into master Jun 5, 2014
@shunter shunter deleted the referenceProperties branch June 5, 2014 21:21
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

Successfully merging this pull request may close these issues.

2 participants