Repository navigation
Deprecate PromiseProxyMixin, Enumerable, and Observable (mixins, RFC#… #21588
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
Open
NullVoxPopuli
wants to merge
5
commits into
main
Choose a base branch
from
nvp/deprecate-mixin-followups
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,622
−1,985
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cb7416c
Move internally-used mixins to internal copies
NullVoxPopuli 4fcb39e
Attempt to guard the isProxy guard in each-in
NullVoxPopuli b5641c6
Add missing @deprecated
NullVoxPopuli d7863d8
Use the public mixins in tests, not the internal copies
NullVoxPopuli 44e5959
Fix the assertion count in the TargetActionSupport tests
NullVoxPopuli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
|
kategengler marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
packages/@ember/-internals/runtime/lib/mixins/-proxy-internal.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| /** | ||
| @module ember | ||
| */ | ||
|
|
||
| import { meta } from '@ember/-internals/meta/lib/meta'; | ||
| import { InternalMixin } from '@ember/object/mixin-internal'; | ||
| import { get } from '@ember/-internals/metal/lib/property_get'; | ||
| import { set } from '@ember/-internals/metal/lib/property_set'; | ||
| import { defineProperty } from '@ember/-internals/metal/lib/properties'; | ||
| import { tagForObject, tagForProperty } from '@ember/-internals/metal/lib/tags'; | ||
| import computed from '@ember/-internals/metal/lib/computed'; | ||
| import { setProxy, isProxy } from '@ember/-internals/utils/lib/is_proxy'; | ||
| import { setupMandatorySetter } from '@ember/-internals/utils/lib/mandatory-setter'; | ||
| import { isObject } from '@ember/-internals/utils/lib/spec'; | ||
| import { assert } from '@ember/debug'; | ||
| import { DEBUG } from '@glimmer/env'; | ||
| import { setCustomTagFor } from '@glimmer/manager/lib/util/args-proxy'; | ||
| import type { UpdatableTag, Tag } from '@glimmer/interfaces'; | ||
| import { combine, UPDATE_TAG as updateTag } from '@glimmer/validator/lib/validators'; | ||
| import { tagFor, tagMetaFor } from '@glimmer/validator/lib/meta'; | ||
|
|
||
| export function contentFor<T>(proxy: { content: T | null }): T | null { | ||
| let content = get(proxy, 'content'); | ||
| // SAFETY: Ideally we'd assert instead of casting, but @glimmer/validator doesn't give us | ||
| // sufficient public types for this. Previously this code was .js and worked correctly so | ||
| // hopefully this is sufficiently reliable. | ||
| updateTag(tagForObject(proxy) as UpdatableTag, tagForObject(content)); | ||
| return content; | ||
| } | ||
|
|
||
| function customTagForProxy(proxy: object, key: string, addMandatorySetter?: boolean): Tag { | ||
| assert('Expected a proxy', isProxy(proxy)); | ||
|
|
||
| let meta = tagMetaFor(proxy); | ||
| let tag = tagFor(proxy, key, meta); | ||
|
|
||
| if (DEBUG) { | ||
| // TODO: Replace this with something more first class for tracking tags in DEBUG | ||
| // SAFETY: This is not an officially supported property but setting shouldn't cause issues. | ||
| (tag as any)._propertyKey = key; | ||
| } | ||
|
|
||
| if (key in proxy) { | ||
| if (DEBUG && addMandatorySetter) { | ||
| assert('[BUG] setupMandatorySetter should be set when debugging', setupMandatorySetter); | ||
| setupMandatorySetter(tag, proxy, key); | ||
| } | ||
|
|
||
| return tag; | ||
| } else { | ||
| let tags: Tag[] = [tag, tagFor(proxy, 'content', meta)]; | ||
|
|
||
| let content = contentFor(proxy); | ||
|
|
||
| if (isObject(content)) { | ||
| tags.push(tagForProperty(content, key, addMandatorySetter)); | ||
| } | ||
|
|
||
| return combine(tags); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| The internal counterpart to the public `ProxyMixin`. Ember's own internals | ||
| apply this so that they do not trigger the deprecation that the public | ||
| mixin emits. The public API documentation lives on the public copy. | ||
|
|
||
| @internal | ||
| */ | ||
| const InternalProxyMixin = /*@__PURE__*/ InternalMixin.create({ | ||
| /** | ||
| The object whose properties will be forwarded. | ||
|
|
||
| @property content | ||
| @type {unknown} | ||
| @default null | ||
| */ | ||
| content: null, | ||
|
|
||
| init() { | ||
| this._super(...arguments); | ||
| setProxy(this); | ||
| tagForObject(this); | ||
| setCustomTagFor(this, customTagForProxy); | ||
| }, | ||
|
|
||
| willDestroy() { | ||
| this.set('content', null); | ||
| this._super(...arguments); | ||
| }, | ||
|
|
||
| isTruthy: computed('content', function () { | ||
| return Boolean(get(this, 'content')); | ||
| }), | ||
|
|
||
| unknownProperty(key: string) { | ||
| let content = contentFor(this); | ||
| return content ? get(content, key) : undefined; | ||
| }, | ||
|
|
||
| setUnknownProperty(key: string, value: unknown) { | ||
| let m = meta(this); | ||
|
|
||
| if (m.isInitializing() || m.isPrototypeMeta(this)) { | ||
| // if marked as prototype or object is initializing then just | ||
| // defineProperty rather than delegate | ||
| defineProperty(this, key, null, value); | ||
| return value; | ||
| } | ||
|
|
||
| let content = contentFor(this); | ||
|
|
||
| assert( | ||
| `Cannot delegate set('${key}', ${value}) to the 'content' property of object proxy ${this}: its 'content' is undefined.`, | ||
| content | ||
| ); | ||
|
|
||
| // SAFETY: We don't actually guarantee that this is an object, so this isn't necessarily safe :( | ||
| return set(content as object, key, value); | ||
| }, | ||
| }); | ||
|
|
||
| export default InternalProxyMixin; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.