Skip to content

Commit 1672b6e

Browse files
pigwangliximomo
authored andcommitted
fix: make __ob__ unenumerable (#149)
* fix: make __ob__ unenumerable
1 parent bb1e030 commit 1672b6e

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/reactivity/reactive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export function nonReactive<T = any>(obj: T): T {
152152
}
153153

154154
// set the vue observable flag at obj
155-
(obj as any).__ob__ = (observe({}) as any).__ob__;
155+
def(obj, '__ob__', (observe({}) as any).__ob__);
156156
// mark as nonReactive
157157
def(obj, NonReactiveIdentifierKey, NonReactiveIdentifier);
158158

test/setup.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,24 @@ describe('setup', () => {
276276
.then(done);
277277
});
278278

279+
it("should put a unenumerable '__ob__' for non-reactive object", () => {
280+
const clone = obj => JSON.parse(JSON.stringify(obj));
281+
const componentSetup = jest.fn(props => {
282+
const internalOptions = clone(props.options);
283+
return { internalOptions };
284+
});
285+
const ExternalComponent = {
286+
props: ['options'],
287+
setup: componentSetup,
288+
};
289+
new Vue({
290+
components: { ExternalComponent },
291+
setup: () => ({ options: {} }),
292+
template: `<external-component :options="options"></external-component>`,
293+
}).$mount();
294+
expect(componentSetup).toReturn();
295+
});
296+
279297
it('current vue should exist in nested setup call', () => {
280298
const spy = jest.fn();
281299
new Vue({

0 commit comments

Comments
 (0)