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

Problems with elgg/Ajax (unreleased in 2.x) #9404

Closed
mrclay opened this Issue Feb 21, 2016 · 1 comment

Comments

Projects
None yet
1 participant
@mrclay
Member

mrclay commented Feb 21, 2016

A big goal of elgg/Ajax is collaboration via hooks on the request and response data. However...

  1. Both server and client-side, the hooks only have access to the value returned by the original ajax handler. This value could be a string (e.g. view) or an array, so hook handlers wanting to piggyback on the response have to wrap the data in an object and unwrap it client-side. If multiple handlers do this, there's plenty of opportunity for error.
  2. Client-side, if a success function is supplied, then the response data hook is called twice (once before the function, once filtering the $.Deferred returned). I told myself this was harmless but even the unwrap_data function has to workaround not setting system messages twice; that should've put up a red flag.

Instead of handling system messages in the internals, I'll use the hooks and send a PR with the API changes that fall out of that work.

@mrclay mrclay added this to the Elgg 2.x milestone Feb 21, 2016

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Feb 21, 2016

chore(ajax): Makes the elgg/Ajax API more reliable and documented
This normalizes the response data to an object server-side containing the
property `value`. This allows other properties to be used reliably to send
metadata back to the client without wrapping the value or other hacks, and
these other properties are only available to response hook listeners. In
effect this provides a cleaner "back channel" for plugins to piggyback on
responses.

Prevents the client-side response hook from firing twice.

Moves the system message delivery to hooks (like plugins would use).

Documents using hooks to filter requests and responses.

Fixes #9404
@mrclay

This comment has been minimized.

Show comment
Hide comment
@mrclay
Member

mrclay commented Feb 21, 2016

PR #9405

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Feb 21, 2016

chore(ajax): Makes the elgg/Ajax API more reliable and documented
This normalizes the response data to an object server-side containing the
property `value`. This allows other properties to be used reliably to send
metadata back to the client without wrapping the value or other hacks, and
these other properties are only available to response hook listeners. In
effect this provides a cleaner "back channel" for plugins to piggyback on
responses.

Prevents the client-side response hook from firing twice.

Moves the system message delivery to hooks (like plugins would use).

Documents using hooks to filter requests and responses.

Fixes #9404

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Feb 21, 2016

chore(ajax): Makes the elgg/Ajax API more reliable and documented
This normalizes the response data to an object server-side containing the
property `value`. This allows other properties to be used reliably to send
metadata back to the client without wrapping the value or other hacks, and
these other properties are only available to response hook listeners. In
effect this provides a cleaner "back channel" for plugins to piggyback on
responses.

Prevents the client-side response hook from firing twice.

Moves the system message delivery to hooks (like plugins would use).

Documents using hooks to filter requests and responses.

Fixes #9404

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Feb 21, 2016

chore(ajax): Makes the elgg/Ajax API more reliable and documented
This normalizes the response data to an object server-side containing the
property `value`. This allows other properties to be used reliably to send
metadata back to the client without wrapping the value or other hacks, and
these other properties are only available to response hook listeners. In
effect this provides a cleaner "back channel" for plugins to piggyback on
responses.

Prevents the client-side response hook from firing twice.

Moves the system message delivery to hooks (like plugins would use).

Documents using hooks to filter requests and responses.

Fixes #9404

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Feb 21, 2016

chore(ajax): Makes the elgg/Ajax API more reliable and documented
This normalizes the response data to an object server-side containing the
property `value`. This allows other properties to be used reliably to send
metadata back to the client without wrapping the value or other hacks, and
these other properties are only available to response hook listeners. In
effect this provides a cleaner "back channel" for plugins to piggyback on
responses.

Prevents the client-side response hook from firing twice.

Moves the system message delivery to hooks (like plugins would use).

Documents using hooks to filter requests and responses.

Fixes #9404

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Feb 21, 2016

chore(ajax): Makes the elgg/Ajax API more reliable and documented
This normalizes the response data to an object server-side containing the
property `value`. This allows other properties to be used reliably to send
metadata back to the client without wrapping the value or other hacks, and
these other properties are only available to response hook listeners. In
effect this provides a cleaner "back channel" for plugins to piggyback on
responses.

Prevents the client-side response hook from firing twice.

Moves the system message delivery to hooks (like plugins would use).

Documents using hooks to filter requests and responses.

Fixes #9404

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Feb 21, 2016

chore(ajax): Makes the elgg/Ajax API more reliable and documented
This normalizes the response data to an object server-side containing the
property `value`. This allows other properties to be used reliably to send
metadata back to the client without wrapping the value or other hacks, and
these other properties are only available to response hook listeners. In
effect this provides a cleaner "back channel" for plugins to piggyback on
responses.

Prevents the client-side response hook from firing twice.

Moves the system message delivery to hooks (like plugins would use).

Documents using hooks to filter requests and responses.

Fixes #9404

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Feb 21, 2016

feature(ajax): improves the elgg/Ajax API and adds docs
Modifies the response hooks API so that handlers receive a wrapper object
rather than the simple return value. This allows handlers to more reliably
attach metadata to the response without the need to "wrap" the value.

Requests can specify that system messages be left in the queue. This is
sometimes desirable if the client code intends to redirect/reload a page.

Prefixes with `elgg_` the server-side options.

The client-side response hook no longer fires twice.

Moves the system message delivery to hooks.

Documents using hooks to filter requests and responses.

Fixes #9404

@mrclay mrclay closed this in #9405 Feb 22, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment