wu

Reactive, functional and declarative framework for webapps

View the Project on GitHub migueldelmazo/wu

Wu framework: Setter documentation

Setter allows you to define an interface to save data from outside to the Wu data model.

Data flow:

Third-party libraries ➤ Setter (pure function) ➤ Reactive data model. Pattern

Ensurer definition properties:

| Properties | Required | |:—————————————————-:|:——–:| | args | Optional | | run | Optional | | update | Required |

Example: passing all the arguments from third-party library

// file user.js
wu.create('setter', 'userSendLoginData', { // name of the setter item
  // pure function
  run: (email, password) => {
    return {
      email,
      password
    }
  },
  // path of the data model where to save the result of 'run'
  update: 'user.login.data'
})

// file userLogin.template.js
sendLoginData () {
  wu.setter('userSendLoginData', 'email@email.com', '12345678')
}

// when 'sendLoginData' is executed 'user.login.data' will have { email: 'email@email.com', password: '12345678' }

Example: passing first argument from data model and second argument from third-party library

// file user.js
wu.create('setter', 'userSendLoginData', { // name of the setter item
  // arguments that will receive the function 'run'
  args: 'user.profile.email',
  // pure function
  run: (email, password) => {
    return {
      email,
      password
    }
  },
  // path of the data model where to save the result of 'run'
  update: 'user.login.data'
})

// file userLogin.template.js
sendLoginData () {
  wu.setter('userSendLoginData', '12345678')
}

// when 'sendLoginData' is executed 'user.login.data' will have { email: 'email@email.com', password: '12345678' }

Example: without run function

// file user.js
wu.create('setter', 'userSendLoginData', { // name of the setter item
  // if 'run' function is not specified, the default function is (arg) => arg
  // it means, the function returns the first argument that receives
  update: 'user.login.data'
})

// file userLogin.template.js
sendLoginData () {
  wu.setter('userSendLoginData', {
    email: 'email@email.com',
    password: '12345678'
  })
}

// when 'sendLoginData' is executed 'user.login.data' will have { email: 'email@email.com', password: '12345678' }