You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

updateEntityDataInContentState.js.flow 858 B

3 years ago
1234567891011121314151617181920212223242526272829
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. * @flow strict-local
  9. * @emails oncall+draft_js
  10. */
  11. 'use strict';
  12. import type ContentState from "./ContentState";
  13. function updateEntityDataInContentState(contentState: ContentState, key: string, data: {
  14. [key: string]: mixed,
  15. ...
  16. }, merge: boolean): ContentState {
  17. const instance = contentState.getEntity(key);
  18. const entityData = instance.getData();
  19. const newData = merge ? { ...entityData,
  20. ...data
  21. } : data;
  22. const newInstance = instance.set('data', newData);
  23. const newEntityMap = contentState.getEntityMap().set(key, newInstance);
  24. return contentState.set('entityMap', newEntityMap);
  25. }
  26. module.exports = updateEntityDataInContentState;