basic.js 798 B

1234567891011121314151617181920212223242526
  1. export const basic = Behavior({
  2. methods: {
  3. $emit(name, detail, options) {
  4. this.triggerEvent(name, detail, options);
  5. },
  6. set(data) {
  7. this.setData(data);
  8. return new Promise((resolve) => wx.nextTick(resolve));
  9. },
  10. // high performance setData
  11. setView(data, callback) {
  12. const target = {};
  13. let hasChange = false;
  14. Object.keys(data).forEach((key) => {
  15. if (data[key] !== this.data[key]) {
  16. target[key] = data[key];
  17. hasChange = true;
  18. }
  19. });
  20. if (hasChange) {
  21. return this.setData(target, callback);
  22. }
  23. return callback && callback();
  24. },
  25. },
  26. });