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

A test case to show how to use a symbol as an attribute name #1626

Merged

Conversation

larry-x-yu
Copy link
Collaborator

@larry-x-yu larry-x-yu commented Jun 13, 2022

[Fix #1569]

Summary of change

  1. Added a test case to show how to use a symbol as an attribute name in emer-m3.

Testing
All test cases (yarn test) passed in local setup.

Comment on lines 11 to 23
class TestSchema extends DefaultSchema {
includesModel(modelName) {
return /^com.example.bookstore\./i.test(modelName);
}
setAttribute(modelName, attr, value, schemaInterface) {
if (attr === 'name') {
schemaInterface.setAttr('title', value);
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we're opting in to the native proxy here.

You need something like

useNativeProperties() { return true; }

see https://github.com/hjdivad/ember-m3#api

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This setting seems to be not necessary in this use case, but it also doesn't hurt too.

Comment on lines 37 to 40
const mySymbol = Symbol('mySymbol');
book.set(mySymbol, book.id);

assert.equal(book.get(mySymbol), 'urn:li:book:1', 'Reading a symbol attribute should work');
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should be testing the native proxy and not calling get / set but rather

book[mySymbol] = book.id
assert.equal(book[mySymbol], 'urn:li:book:1')

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point! If we opt to use this format, the test case can pass successfully without any other change in other files.

Do you think we should simply add something in README to the effect like the below:

When using symbols as attribute names, please be sure to use the format of model[mySymbol]. set() and get() are known to have issues.

Another option is me/somebody else to fix the proxy in ember, so that both the .[] and set/get can be used interchangeably.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@larry-x-yu I don't think we need docs for symbols specifically.

The thing we can do to make things better is to drop CoreObject as a superclass in model, but it'll be a breaking change.

@larry-x-yu larry-x-yu force-pushed the laryu/m3-proxy-to-not-intercept-symbols branch 2 times, most recently from 9ca404f to bbc9cd6 Compare June 14, 2022 17:58
@larry-x-yu larry-x-yu force-pushed the laryu/m3-proxy-to-not-intercept-symbols branch from 708afca to 6b878ac Compare June 15, 2022 16:50
@larry-x-yu larry-x-yu changed the title Proxy not to intercept symbols A test case to show how to use a symbol as an attribute name in emer-m3 Jun 15, 2022
@larry-x-yu larry-x-yu changed the title A test case to show how to use a symbol as an attribute name in emer-m3 A test case to show how to use a symbol as an attribute name Jun 15, 2022
@larry-x-yu larry-x-yu added documentation ch:documentation and removed enhancement ch:enhancement labels Jun 15, 2022
@larry-x-yu larry-x-yu requested a review from hjdivad June 15, 2022 16:55
@hjdivad hjdivad merged commit 80399eb into ember-m3:master Jun 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation ch:documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Native proxy intercepts symbols in tests for attribute access
2 participants