Skip to content

Commit

Permalink
fix(): mutable() fix/store obj (QwikDev#1232)
Browse files Browse the repository at this point in the history
  • Loading branch information
samijaber authored Sep 14, 2022
1 parent fe9da48 commit 44928c0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
27 changes: 14 additions & 13 deletions packages/qwik/src/core/object/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,20 +340,21 @@ export const _pauseFromContexts = async (

const getObjId = (obj: any): string | null => {
let suffix = '';
if (isObject(obj)) {
if (isMutable(obj)) {
obj = obj.mut;
suffix = '%';
}
if (isPromise(obj)) {
const { value, resolved } = getPromiseValue(obj);
obj = value;
if (resolved) {
suffix += '~';
} else {
suffix += '_';
}
if (isMutable(obj)) {
obj = obj.mut;
suffix = '%';
}
if (isPromise(obj)) {
const { value, resolved } = getPromiseValue(obj);
obj = value;
if (resolved) {
suffix += '~';
} else {
suffix += '_';
}
}

if (isObject(obj)) {
const target = getProxyTarget(obj);
if (target) {
suffix += '!';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { component$, $, useStore, mutable, noSerialize } from '@builder.io/qwik';

export const LexicalScope = component$(() => {
return <LexicalScopeChild message={mutable('mutable message')}></LexicalScopeChild>;
return <LexicalScopeChild message={mutable('mutable message')} message2={mutable(null)} />;
});

interface LexicalScopeProps {
message: string;
message2: string | null;
}

export const LexicalScopeChild = component$((props: LexicalScopeProps) => {
Expand Down Expand Up @@ -68,6 +69,7 @@ export const LexicalScopeChild = component$((props: LexicalScopeProps) => {
h,
i,
props.message,
props.message2,
promiseValue,
url.href,
date.toISOString(),
Expand Down
2 changes: 1 addition & 1 deletion starters/e2e/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test.describe('e2e', () => {
const SNAPSHOT =
'<p>1</p><p>"&lt;/script&gt;"</p><p>{"a":{"thing":12},"b":"hola","c":123,"d":false,"e":true,"f":null,"h":[1,"string",false,{"hola":1},["hello"]],"promise":{}}</p><p>undefined</p><p>null</p><p>[1,2,"hola",null,{}]</p><p>true</p><p>false</p><p>()=&gt;console.error()</p><p>mutable message</p><p>from a promise</p>';
const RESULT =
'[1,"</script>",{"a":{"thing":12},"b":"hola","c":123,"d":false,"e":true,"f":null,"h":[1,"string",false,{"hola":1},["hello"]],"promise":{}},"undefined","null",[1,2,"hola",null,{}],true,false,null,"mutable message","from a promise","http://qwik.builder.com/docs?query=true","2022-07-26T17:40:30.255Z","hola()\\\\/ gi",12,"failed message",["\\b: backspace","\\f: form feed","\\n: line feed","\\r: carriage return","\\t: horizontal tab","\\u000b: vertical tab","\\u0000: null character","\': single quote","\\\\: backslash"]]';
'[1,"</script>",{"a":{"thing":12},"b":"hola","c":123,"d":false,"e":true,"f":null,"h":[1,"string",false,{"hola":1},["hello"]],"promise":{}},"undefined","null",[1,2,"hola",null,{}],true,false,null,"mutable message",null,"from a promise","http://qwik.builder.com/docs?query=true","2022-07-26T17:40:30.255Z","hola()\\\\/ gi",12,"failed message",["\\b: backspace","\\f: form feed","\\n: line feed","\\r: carriage return","\\t: horizontal tab","\\u000b: vertical tab","\\u0000: null character","\': single quote","\\\\: backslash"]]';

function normalizeSnapshot(str: string) {
return str.replace(' =&gt; ', '=&gt;');
Expand Down

0 comments on commit 44928c0

Please sign in to comment.