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

Add getter function for Properties #1570

Merged
merged 1 commit into from
Nov 10, 2015
Merged

Add getter function for Properties #1570

merged 1 commit into from
Nov 10, 2015

Conversation

michalvankodev
Copy link
Contributor

I'd like to attach listeners to the properties of Properties via PropertyHelper to avoid memory leaks.
PropertyHelper accepts only Property objects as arguments.

@dchambers
Copy link
Contributor

Hi @michalvankodev,

Properties already has an addListener(listener) method, where listener supports the following callbacks:

  • onPropertyUpdated
  • onPropertyChanged
  • onValidationSuccess
  • onValidationError
  • onValidationComplete

If these aren't sufficient for what you need could you please provide some more context so we can better understand your actual needs? Or, perhaps you can link the commit where you fix the memory leak you're seeing?

@michalvankodev
Copy link
Contributor Author

Hi @dchambers I am not fixing a memory leak. I'm avoiding creating one with usage of PropertyHelper which will track properties I attach listeners to. As I am using SLJSContainerManager I have no control of the properties which I attach listeners to as those can be removed at any time. So I attach listeners via PropertyHelper which allows me to remove listeners easily. I just need to get the instance of the Property and not Properties as PropertyHelper only accepts those.

@dchambers
Copy link
Contributor

Hi @michalvankodev, any chance you could point me to the code snippet in question so I can take a look for myself?

@dchambers
Copy link
Contributor

Sorry for the delay @michalvankodev, I've only just now had a chance to look at this. AFAICT, this is the relevant bit of code:

XXXPM.prototype._setUpNodeListeners = function() {
    var nodes = this.rows.getPresentationNodesArray();

    this._propertyHelper.removeAllListeners();

    nodes.forEach(function(node) {
        var properties = node.properties().getProperties();

        properties.forEach(function(prop) {
            this._propertyHelper.addChangeListener(prop, this, '_onNodesChanged', false);
        }, this);
    }, this);
};

Excuse my ignorance, but what is PropertyHelper and why are we using it? It's not currently clear to me what it adds over just using Property directly.

@dchambers
Copy link
Contributor

@michalvankodev, could you please change your method to this:

Properties.prototype.getProperties = function() {
    return this.m_pProperties.slice(0);
};

so that the original can't be mutated.

@dchambers
Copy link
Contributor

Thanks @michalvankodev 👍

@thecapdan thecapdan merged commit 6a09746 into BladeRunnerJS:master Nov 10, 2015
@thecapdan thecapdan modified the milestones: 2.0.0, Current Focus Nov 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants