Skip to content

Manage Data

Arthur Guiot edited this page May 12, 2018 · 3 revisions

In ProType, you'll be able to share data between class and handling changes correctly. There are multiple ways of handling data, here are them:

Workspaces

A workspace is an object that every class such as Views, Groups or Components can get and update its value.

Here is how you use it:

const P = new ProType();

P.workspace // {}

P.workspace = {
    clientID: 4269 // some random data
}

Pipelines

A pipeline is a property that you can access in the current View. Every Group or Component (and the View itself) can access this property like that:

const P = new ProType();

P.pipeline // {}

P.setPipeline({
     data: "Some data"
})

Handling Pipeline changes

When P.setPipeline() is called, your current ViewController method onPipelineChange() will be called.

Your ViewController should look like:

class MainController extends P.ViewController { // name your controller as you want
	willShow(sender = "Main") {
		// perform action when the controller is showing up
	}
	willDisappear(sender = "Main") {
		// perform an action when the controller is disappearing
	}
        // optional:
        onPipelineChange(pipeline) {
            // Do something when the pipeline changed
        }
}

State

A state is a way of keeping data in a Group. A state won't be shared across other class.

Here is how it works:

class Group extends P.Groups {
     init() {
          console.log(this.state) // {}
          this.setState({
              hello: "World 🌎"
          })
     }
     changeHandler(state) {
         // Will be activated when 'this.setState' is called
     }
}

Next: Router

Clone this wiki locally