bigskysoftware / intercooler-js

Making AJAX as easy as anchor tags
http://intercoolerjs.org
MIT License
4.78k stars 235 forks source link

Include values from browser local storage in requests #101

Closed jpincas closed 8 years ago

jpincas commented 8 years ago

Noticed Carson said he was looking at doing a new release in June, and I realised I forgot to come back to this when we were talking about it last month. Here's a few simple lines of code I'm using to make any local storage key available in the declarative 'Intercooler' way with a new attribute 'ic-include-ls-key':

var lsKey = closestAttrValue(elt, 'ic-include-ls-key'); if (lsKey) { data = appendData(data, lsKey, localStorage.getItem(lsKey)); }

I'm using it in my e-commerce platform to send up the identifier for a user's cart.

Do people think it's a useful enough feature to include?

1cg commented 8 years ago

Hi Jonathan,

I think I’d like to work through including local storage data as well as setting it, maybe via a header?

Proposal

  attribute: ic-local-vars=“foo, bar, do” // sent up wiith request

  header: X-IC-Set-Local-Vars=“{“foo” : 10, “bar” : 42}”  // sets the local storage vars

How does that look?

Cheers, Carson

On June 16, 2016 at 12:13:49 AM, Jonathan Pincas (notifications@github.com) wrote:

Noticed Carson said he was looking at doing a new release in June, and I realised I forgot to come back to this when we were talking about it last month. Here's a few simple lines of code I'm using to make any local storage key available in the declarative 'Intercooler' way with a new attribute 'ic-include-ls-key':

var lsKey = closestAttrValue(elt, 'ic-include-ls-key'); if (lsKey) { data = appendData(data, lsKey, localStorage.getItem(lsKey)); }

I'm using it in my e-commerce platform to send up the identifier for a user's cart.

Do people think it's a useful enough feature to include?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

jpincas commented 8 years ago

Proposal

attribute: ic-local-vars=“foo, bar, do” // sent up with request

Perfect - so this would enable us to send up multiple values if I’m interpreting correctly!

header: X-IC-Set-Local-Vars=“{“foo” : 10, “bar” : 42}” // sets the local storage vars

Much better solution to what I’m currently doing (rendering the value as a ‘data’ attribute in the main div of the returned HTML and using a JS script to pick up the value and set it in local storage)

In summary - great stuff. I really feel that with the advent of JWT authentication with locally stored tokens, this type of functionality gives Intercooler a real edge.

Thanks

Jon

How does that look?

Cheers, Carson

On June 16, 2016 at 12:13:49 AM, Jonathan Pincas (notifications@github.com) wrote:

Noticed Carson said he was looking at doing a new release in June, and I realised I forgot to come back to this when we were talking about it last month. Here's a few simple lines of code I'm using to make any local storage key available in the declarative 'Intercooler' way with a new attribute 'ic-include-ls-key':

var lsKey = closestAttrValue(elt, 'ic-include-ls-key'); if (lsKey) { data = appendData(data, lsKey, localStorage.getItem(lsKey)); }

I'm using it in my e-commerce platform to send up the identifier for a user's cart.

Do people think it's a useful enough feature to include?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/LeadDyno/intercooler-js/issues/101#issuecomment-226566392, or mute the thread https://github.com/notifications/unsubscribe/AQ4_pAF8RwyPfhoJ7eRWEpnmkH-pkonLks5qMZEYgaJpZM4I3FxK.

1cg commented 8 years ago

localStorage API:

  https://github.com/LeadDyno/intercooler-js/commit/e83a1ff76a5c3d9c97c2bb63ee707eda1b100496

Targeting release next Friday.

Cheers, Carson

On June 17, 2016 at 1:22:40 AM, Jonathan Pincas (notifications@github.com) wrote:

Proposal

attribute: ic-local-vars=“foo, bar, do” // sent up with request

Perfect - so this would enable us to send up multiple values if I’m interpreting correctly!

header: X-IC-Set-Local-Vars=“{“foo” : 10, “bar” : 42}” // sets the local storage vars

Much better solution to what I’m currently doing (rendering the value as a ‘data’ attribute in the main div of the returned HTML and using a JS script to pick up the value and set it in local storage)

In summary - great stuff. I really feel that with the advent of JWT authentication with locally stored tokens, this type of functionality gives Intercooler a real edge.

Thanks

Jon

How does that look?

Cheers, Carson

On June 16, 2016 at 12:13:49 AM, Jonathan Pincas (notifications@github.com) wrote:

Noticed Carson said he was looking at doing a new release in June, and I realised I forgot to come back to this when we were talking about it last month. Here's a few simple lines of code I'm using to make any local storage key available in the declarative 'Intercooler' way with a new attribute 'ic-include-ls-key':

var lsKey = closestAttrValue(elt, 'ic-include-ls-key'); if (lsKey) { data = appendData(data, lsKey, localStorage.getItem(lsKey)); }

I'm using it in my e-commerce platform to send up the identifier for a user's cart.

Do people think it's a useful enough feature to include?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/LeadDyno/intercooler-js/issues/101#issuecomment-226566392, or mute the thread https://github.com/notifications/unsubscribe/AQ4_pAF8RwyPfhoJ7eRWEpnmkH-pkonLks5qMZEYgaJpZM4I3FxK.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

1cg commented 8 years ago

That's a great feature for embedding the API key in localstorage and keeping it out of band.

On Friday, June 17, 2016 at 1:12:22 PM UTC-4, Carson Gross wrote:

localStorage API:

https://github.com/LeadDyno/intercooler-js/commit/e83a1ff76a5c3d9c97c2bb63ee707eda1b100496

https://github.com/LeadDyno/intercooler-js/commit/e83a1ff76a5c3d9c97c2bb63ee707eda1b100496

Targeting release next Friday.

Cheers, Carson

On June 17, 2016 at 1:22:40 AM, Jonathan Pincas (notifi...@github.com

) wrote: Proposal > attribute: ic-local-vars=“foo, bar, do” // sent up with request Perfect - so this would enable us to send up multiple values if I’m interpreting correctly! > header: X-IC-Set-Local-Vars=“{“foo” : 10, “bar” : 42}” // sets the local > storage vars Much better solution to what I’m currently doing (rendering the value as a ‘data’ attribute in the main div of the returned HTML and using a JS script to pick up the value and set it in local storage) In summary - great stuff. I really feel that with the advent of JWT authentication with locally stored tokens, this type of functionality gives Intercooler a real edge. Thanks Jon > How does that look? > > Cheers, > Carson > > On June 16, 2016 at 12:13:49 AM, Jonathan Pincas (notifi...@github.com > ) wrote: > > Noticed Carson said he was looking at doing a new release in June, and I > realised I forgot to come back to this when we were talking about it last > month. Here's a few simple lines of code I'm using to make any local > storage key available in the declarative 'Intercooler' way with a new > attribute 'ic-include-ls-key': > > var lsKey = closestAttrValue(elt, 'ic-include-ls-key'); > if (lsKey) { > data = appendData(data, lsKey, localStorage.getItem(lsKey)); > } > > I'm using it in my e-commerce platform to send up the identifier for a > user's cart. > > Do people think it's a useful enough feature to include? > > — > You are receiving this because you are subscribed to this thread. > Reply to this email directly, view it on GitHub, or mute the thread. > > — > You are receiving this because you authored the thread. > Reply to this email directly, view it on GitHub < > https://github.com/LeadDyno/intercooler-js/issues/101#issuecomment-226566392>, > or mute the thread < > https://github.com/notifications/unsubscribe/AQ4_pAF8RwyPfhoJ7eRWEpnmkH-pkonLks5qMZEYgaJpZM4I3FxK > . — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/LeadDyno/intercooler-js/issues/101#issuecomment-226710213, or mute the thread https://github.com/notifications/unsubscribe/AAcov8xi7oS6DIQP7mUwR23SVopxg3KQks5qMllOgaJpZM4I3FxK .