@fluidframework/map 2.0.0-rc.2.0.6 → 2.0.0-rc.2.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -103,19 +103,16 @@ export class PlainLocalValue implements ILocalValue {
103
103
  export class LocalValueMaker {
104
104
  /**
105
105
  * Create a new LocalValueMaker.
106
+ * @param serializer - The serializer to serialize / parse handles.
106
107
  */
107
- public constructor() {}
108
+ public constructor(private readonly serializer: IFluidSerializer) {}
108
109
 
109
110
  /**
110
111
  * Create a new local value from an incoming serialized value.
111
112
  * @param serializable - The serializable value to make local
112
113
  */
113
- public fromSerializable(
114
- // eslint-disable-next-line import/no-deprecated
115
- serializable: ISerializableValue,
116
- serializer: IFluidSerializer,
117
- bind: IFluidHandle,
118
- ): ILocalValue {
114
+ // eslint-disable-next-line import/no-deprecated
115
+ public fromSerializable(serializable: ISerializableValue): ILocalValue {
119
116
  // Migrate from old shared value to handles
120
117
  if (serializable.type === ValueType[ValueType.Shared]) {
121
118
  serializable.type = ValueType[ValueType.Plain];
@@ -123,14 +120,12 @@ export class LocalValueMaker {
123
120
  type: "__fluid_handle__",
124
121
  url: serializable.value as string,
125
122
  };
126
- // NOTE: here we require the use of `parseHandles` because the roundtrip
127
- // through a string is necessary to resolve the absolute path of
128
- // legacy handles (`ValueType.Shared`)
129
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
130
- serializable.value = serializer.encode(parseHandles(handle, serializer), bind);
123
+ serializable.value = handle;
131
124
  }
132
125
 
133
- return new PlainLocalValue(serializable.value);
126
+ const translatedValue: unknown = parseHandles(serializable.value, this.serializer);
127
+
128
+ return new PlainLocalValue(translatedValue);
134
129
  }
135
130
 
136
131
  /**
package/src/mapKernel.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  import { IFluidHandle } from "@fluidframework/core-interfaces";
7
- import { IFluidSerializer, ValueType, bindHandles } from "@fluidframework/shared-object-base";
7
+ import { IFluidSerializer, ValueType } from "@fluidframework/shared-object-base";
8
8
  import { assert, unreachableCase } from "@fluidframework/core-utils";
9
9
  import { TypedEventEmitter } from "@fluid-internal/client-utils";
10
10
  // eslint-disable-next-line import/no-deprecated
@@ -182,7 +182,7 @@ export class MapKernel {
182
182
  private readonly isAttached: () => boolean,
183
183
  private readonly eventEmitter: TypedEventEmitter<ISharedMapEvents>,
184
184
  ) {
185
- this.localValueMaker = new LocalValueMaker();
185
+ this.localValueMaker = new LocalValueMaker(serializer);
186
186
  this.messageHandlers = this.getMessageHandlers();
187
187
  }
188
188
 
@@ -293,23 +293,20 @@ export class MapKernel {
293
293
 
294
294
  // Create a local value and serialize it.
295
295
  const localValue = this.localValueMaker.fromInMemory(value);
296
+ const serializableValue = makeSerializable(localValue, this.serializer, this.handle);
296
297
 
297
298
  // Set the value locally.
298
299
  const previousValue = this.setCore(key, localValue, true);
299
300
 
300
301
  // If we are not attached, don't submit the op.
301
302
  if (!this.isAttached()) {
302
- // this is necessary to bind the potential handles in the value
303
- // to this DDS, as we do not walk the object normally unless we
304
- // are attached
305
- bindHandles(localValue.value, this.serializer, this.handle);
306
303
  return;
307
304
  }
308
305
 
309
306
  const op: IMapSetOperation = {
310
307
  key,
311
308
  type: "set",
312
- value: { type: localValue.type, value: localValue.value as unknown },
309
+ value: serializableValue,
313
310
  };
314
311
  this.submitMapKeyMessage(op, previousValue);
315
312
  }
@@ -390,9 +387,7 @@ export class MapKernel {
390
387
  * @param data - A JSON string containing serialized map data
391
388
  */
392
389
  public populateFromSerializable(json: IMapDataObjectSerializable): void {
393
- for (const [key, serializable] of Object.entries(
394
- this.serializer.decode(json) as IMapDataObjectSerializable,
395
- )) {
390
+ for (const [key, serializable] of Object.entries(json)) {
396
391
  const localValue = {
397
392
  key,
398
393
  value: this.makeLocal(key, serializable),
@@ -402,6 +397,10 @@ export class MapKernel {
402
397
  }
403
398
  }
404
399
 
400
+ public populate(json: string): void {
401
+ this.populateFromSerializable(JSON.parse(json) as IMapDataObjectSerializable);
402
+ }
403
+
405
404
  /**
406
405
  * Submit the given op if a handler is registered.
407
406
  * @param op - The operation to attempt to submit
@@ -592,11 +591,7 @@ export class MapKernel {
592
591
  serializable.type === ValueType[ValueType.Plain] ||
593
592
  serializable.type === ValueType[ValueType.Shared]
594
593
  ) {
595
- return this.localValueMaker.fromSerializable(
596
- serializable,
597
- this.serializer,
598
- this.handle,
599
- );
594
+ return this.localValueMaker.fromSerializable(serializable);
600
595
  } else {
601
596
  throw new Error("Unknown local value type");
602
597
  }
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/map";
9
- export const pkgVersion = "2.0.0-rc.2.0.6";
9
+ export const pkgVersion = "2.0.0-rc.2.0.7";