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

ES6: migrated "entity" (part 2) #1195

Merged
merged 14 commits into from
May 9, 2017
Merged

ES6: migrated "entity" (part 2) #1195

merged 14 commits into from
May 9, 2017

Conversation

bennycode
Copy link
Contributor

Type of change

Screenshot

@lipis lipis mentioned this pull request May 8, 2017
79 tasks
window.z = window.z || {};
window.z.entity = z.entity || {};


Copy link
Contributor

Choose a reason for hiding this comment

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

One too many

this.name = ko.observable();
this.input = ko.observable(z.util.StorageUtil.get_value(`${z.storage.StorageKey.CONVERSATION.INPUT}|${this.id}`) || '');
this.input.subscribe((text) => {
return z.util.StorageUtil.set_value(`${z.storage.StorageKey.CONVERSATION.INPUT}|${this.id}`, text);
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we can keep simply things like this in a single line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It extended our character limit per line:

unbenannt

this.participating_user_ids = ko.observableArray([]);
this.self = undefined;
this.number_of_participants = ko.pureComputed(() => {
return this.participating_user_ids().length;
Copy link
Contributor

Choose a reason for hiding this comment

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

See above

return this.participating_user_ets()[0].name();
}
return '…';
} else if (this.is_group()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for else. You always return in the above if

add_message(message_et) {
amplify.publish(z.event.WebApp.CONVERSATION.MESSAGE.ADDED, message_et);
this._update_last_read_from_message(message_et);
return this.messages_unordered.push(this._check_for_duplicate_nonce(message_et, this.get_last_message()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't return if you return undefined

}
}

return z.util.ko_array_push_all(this.messages_unordered, message_ets);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really want to return this?

message_et = this._check_for_duplicate_nonce(message_ets[index - 1], message_et);
}

return z.util.ko_array_unshift_all(this.messages_unordered, message_ets);
Copy link
Contributor

Choose a reason for hiding this comment

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

Return?

* @returns {undefined} No return value
*/
remove_message(message_et) {
return this.messages_unordered.remove(message_et);
Copy link
Contributor

Choose a reason for hiding this comment

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

Sure we want to return this?

* @returns {undefined} No return value
*/
remove_messages() {
return this.messages_unordered.removeAll();
Copy link
Contributor

Choose a reason for hiding this comment

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

See above

* @note If a message is send to the backend multiple times by a client they will be in the conversation multiple times
* @param {z.entity.Message} message_et - Message entity to be added to the conversation
* @param {z.entity.Message} other_message_et - Other message entity to compare with
* @returns {undefined} No return value
Copy link
Contributor

Choose a reason for hiding this comment

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

You return a message entity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not anymore 🗡

* Creates the placeholder message after clearing a conversation.
* @private
* @note Only create the message if the group participants have been set
* @returns {undefined} No return value
Copy link
Contributor

Choose a reason for hiding this comment

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

You return a message entity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not anymore 🗡

*/
update_latest_from_message(message_et) {
if ((message_et != null) && message_et.visible() && message_et.should_effect_conversation_timestamp) {
return this.set_timestamp(message_et.timestamp(), z.conversation.ConversationUpdateType.LAST_EVENT_TIMESTAMP);
Copy link
Contributor

Choose a reason for hiding this comment

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

Return?

const has_timestamp = message_et.timestamp();

if (is_me && has_timestamp && message_et.should_effect_conversation_timestamp) {
return this.set_timestamp(message_et.timestamp(), z.conversation.ConversationUpdateType.LAST_READ_TIMESTAMP);
Copy link
Contributor

Choose a reason for hiding this comment

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

Return?

return [this.self]
.concat(this.participating_user_ets())
.filter((user_et) => !user_et.is_verified())
.map((user_et) => user_et);
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for this map

Copy link
Contributor

@gregor gregor left a comment

Choose a reason for hiding this comment

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

Please check JSDoc returns and your actual returns

// Conversation states for view
this.is_muted = ko.pureComputed(() => {
return this.muted_state();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest

this.is_muted = ko.pureComputed(() => this.muted_state());

everywhere where functions consist only of one return line.

@bennycode
Copy link
Contributor Author

@gregor & @ffflorian: I fixed all of your requests.

Copy link
Contributor

@ffflorian ffflorian left a comment

Choose a reason for hiding this comment

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

There are more one-liner functions missing which can/should be shortened.

Just replace \) => \{\n +return (.*);\n +\}\); with \) => $1\); 🙂

this.verification_state,
].forEach((property) => {
return property.subscribe(this.persist_state);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

].forEach((property) => property.subscribe(this.persist_state));

this.name = ko.observable('');
this.first_name = ko.pureComputed(() => {
return this.name().split(' ')[0];
});
Copy link
Contributor

Choose a reason for hiding this comment

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

this.first_name = ko.pureComputed(() => this.name().split(' ')[0]);

@bennycode bennycode merged commit d2eea74 into dev May 9, 2017
@bennycode bennycode deleted the es6/entity branch May 9, 2017 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants