top_toggle.js 505 B

123456789101112131415161718192021222324252627
  1. /**
  2. * @author oldj
  3. * @blog https://oldj.net
  4. */
  5. 'use strict'
  6. import Agent from '../Agent'
  7. module.exports = (app, on, on_ids, callback) => {
  8. let list = app.state.list
  9. let new_list = list.map(item => {
  10. let new_item = Object.assign({}, item)
  11. new_item.on = !!(on && on_ids.includes(item.id))
  12. return new_item
  13. })
  14. Agent.pact('saveHosts', new_list)
  15. .then(() => {
  16. app.setState({list: new_list})
  17. //app.forceUpdate()
  18. callback()
  19. })
  20. .catch(e => callback(e))
  21. }