Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support weex #1163

Merged
merged 2 commits into from
Sep 19, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/types/observablearray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,32 @@ function inherit(ctor, proto) {
}
inherit(StubArray, Array.prototype)

// Weex freeze Array.prototype
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

Could you make the patch conditional? That is, only apply the patch if the properties are actually not writable (such as in the weex case)? This avoids putting more methods in the prototype chain when it is not really needed.

// Make them writeable and configurable in prototype chain
// https://github.com/alibaba/weex/pull/1529
if (Object.isFrozen(Array)) {
;[
"constructor",
"push",
"shift",
"concat",
"pop",
"unshift",
"replace",
"find",
"findIndex",
"splice",
"reverse",
"sort"
].forEach(function (key) {
Object.defineProperty(StubArray.prototype, key, {
configurable: true,
writable: true,
value: Array.prototype[key]
})
})
}

class ObservableArrayAdministration<T>
implements IInterceptable<IArrayWillChange<T> | IArrayWillSplice<T>>, IListenable {
atom: BaseAtom
Expand Down