top_toggle.js 578 B

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