# Return all property tree changes

**URL:** <https://forum.inductiveautomation.com/t/return-all-property-tree-changes/42036>\
**Category:** Module Development\
**Created:** [January 7, 2021, 6:25pm UTC](https://forum.inductiveautomation.com/t/return-all-property-tree-changes/42036 "2021-01-07T18:25:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![joehahn](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@joehahn](https://forum.inductiveautomation.com/u/joehahn)\
**Post date:** [January 7, 2021, 6:25pm UTC](https://forum.inductiveautomation.com/t/return-all-property-tree-changes/42036/1 "2021-01-07T18:25:29Z")

</div>

I know that you can return a singe property tree value like this based on the sample :

```auto
 url: tree.readString("url", "")
```

Is there a way I can simply return all the changes at once?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 7, 2021, 7:10pm UTC](https://forum.inductiveautomation.com/t/return-all-property-tree-changes/42036/2 "2021-01-07T19:10:02Z")

</div>

If you’re on 8.1 or higher, there’s a `PropertyTree.subscribe` method.

---

<div class="post-metadata">

**Author:** ![joehahn](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@joehahn](https://forum.inductiveautomation.com/u/joehahn)\
**Post date:** [January 7, 2021, 7:32pm UTC](https://forum.inductiveautomation.com/t/return-all-property-tree-changes/42036/3 "2021-01-07T19:32:31Z")

</div>

Thanks! I’m probably overthinking it is there an example of this usage in the sdk or api where it returns the whole tree?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 7, 2021, 8:17pm UTC](https://forum.inductiveautomation.com/t/return-all-property-tree-changes/42036/4 "2021-01-07T20:17:43Z")

</div>

Actually, I’m probably a terrible person to offer Perspective advice. Maybe @ynejati or @PerryAJ 🙂

---

<div class="post-metadata">

**Author:** ![PerryAJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/perryaj/32/3281_2.png) [@PerryAJ](https://forum.inductiveautomation.com/u/PerryAJ)\
**Post date:** [January 7, 2021, 10:12pm UTC](https://forum.inductiveautomation.com/t/return-all-property-tree-changes/42036/5 "2021-01-07T22:12:35Z")

</div>

Happy to help –

Joe, I’m assuming your snippet above was in your reducer function?

The main thing to realize is that the reducer function returns whatever you want from it. So you could (if you wanted) return the whole property tree.

Depending on the complexity, my suggestion for best testability would be to avoid returning the whole raw `PropertyTree` instance from the reducer. If you need the full tree, it’s probably best to convert it to a plain javascript object using `read()` or `toPlainObject()` first. I’d even recommend passing in any mutation (write) functions as ‘plain props’ rather than property tree elements, as it will help avoid unnecessary tight coupling to the implementation of PropertyTree.

```auto
getPropsReducer(tree: PropertyTree): MyPropType {
    return {
        // will give the property tree as a plain js object, instead of an instance of PropertyTree
        // this would let you read the value of the tree via `this.props.props.json`. Same result occurs if
        // calling tree.read(), without passing a path parameter.
       json: tree.toPlainObject()
      
       
       // If you had to write to the tree's 'data' node, passing in a callback function instead of the actual
       // PropertyTree will simplify unit testability of your component outside of perspective's environment.
       // You would call this via this.props.props.writeData(someNewData)
       writeData: (newJson) -> tree.write("data", newJson)
    }
}

```

That all said, for performance reasons, be careful returning the whole tree even as a plain object. Depending on the nature/implementation of the properties + component, it’s easy to imagine introducing poor performance due to re-rendering when you don’t need to. It’s best to be selective if you can.

---

<div class="post-metadata">

**Author:** ![joehahn](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@joehahn](https://forum.inductiveautomation.com/u/joehahn)\
**Post date:** [January 7, 2021, 10:44pm UTC](https://forum.inductiveautomation.com/t/return-all-property-tree-changes/42036/6 "2021-01-07T22:44:57Z")

</div>

Thanks for your help!  
from the sdk example,

```auto
const { props: { url }, emit } = this.props;
```

is how I have been getting the data in. Should I use the tree.read function instead?

what usage would you recommend for a json prop tree like below?

```auto

{
	"$schema": "http://json-schema.org/draft-04/schema#",
	
	
	
	"Item1": 
		"blabla",
			"type": "object",
	"properties": {
	
		"booleanOne":{
			"default": false
		},

		"Item1":{
			"default":"Text 1"
		},
		"Item2":{
			"default":"Text 2"
		},

	 "text1": {
            "type": "string",
            "description": "text input 1.",
            "default": "blabla 1"
        },	
		
	
	 "text2": {
            "type": "string",
            "description": "text input 1",
            "default": "blabla 2"
        },	
	}
		 ,
	
	"style": {
		"$ref": "urn:ignition-schema:schemas/style-properties.schema.json"
		
	},
    "position": {
          "rotate": {
      
      }
      
    },
    "custom": {}

	}
		

```

---

<div class="post-metadata">

**Author:** ![joehahn](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@joehahn](https://forum.inductiveautomation.com/u/joehahn)\
**Post date:** [January 8, 2021, 1:52pm UTC](https://forum.inductiveautomation.com/t/return-all-property-tree-changes/42036/7 "2021-01-08T13:52:13Z")

</div>

Would this be the correct usage ?  
Using this way, I can change a property value by a binding.  
I bound a text box value to the property.  
In the browser I put “Happy Friday” in the box  
with a button click I print the tree value that was bound.  
I can see that the property tree is updated with the value “Happy Friday”  
however “Happy Friday” is not passed to the object itself.

```
export interface ModProps {
   json: any;

}

```

…

```
render() {
    

 
 const { props } = this.props;
 const json: string = this.props.props.json;
 
 
 use values
 
 
 
 }
 
   getPropsReducer(tree: PropertyTree): ModProps {
    return {
        json: tree.read()
        
        

		
		
    };
```
