Coder Social home page Coder Social logo

solkimicreb / react-easy-params Goto Github PK

View Code? Open in Web Editor NEW
74.0 4.0 2.0 4.11 MB

:link: Auto synchronize your state with the URL and LocalStorage.

License: MIT License

JavaScript 100.00%
front-end url localstorage reactive react state javascript routing es6-proxies

react-easy-params's People

Contributors

solkimicreb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-easy-params's Issues

Support path string similar to `location.pathname`

I'm finding the current path array to be kinda awkward to use in my app. I'm more used to the simple old string path like /path. Which is also the default format in a lot of places and libraries, like location.pathname for example.

Please consider providing the path as a simple string.

Hash paths (#)

It seems paths that start with /# don't work (they aren't reflected in path variable), and also they make params not work either, so example.com/#path?param=value has both path and params empty.

I like using /# paths (instead of actual /path) as they work across simplest of servers and protocols (file://).

Love this lib (and easy-state), can't wait for the unification/merger.

Empty params in url cause Uncaught SyntaxError

Hi there,

Just noticed today that this library doesn't seem to play nicely with empty url search query params.

For example, for the url:

http://localhost:5000/something?event=

I'm getting the following error:

Uncaught SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at toParams (es.es5.js:37)
    at Object.../../node_modules/react-easy-params/dist/es.es5.js (es.es5.js:47)
    at __webpack_require__ (bootstrap:709)

I'm actually not even using the params part of this library at the moment, just the storage part - but it seems to run some kind of setup for the params side of things in any case (I assume the backing stores). Looks like its running into some kind of JSON parsing error when a query param is empty in the url.

In this case I believe the params object should look like so:

{
   event: "",
}

Using the popular query-string library, I get an object like that when I parse the query param part of the url.

Allow disabling of certain features

This kind of a continuation of the last one. Sorry for another issue ๐Ÿ˜…

So as mentioned in the last issue, I wasn't actually using the params side of this library - just the storage.

Would it be possible to provide an option to disable the params side of things? As right now, I'm getting behaviour like this (the params are auto-converting to types as clarified in the last issue):

something?event= -> something?event=""

But in my current use-case, because I'm not actually using the params side of the library and the types it provides using the " (quotations), my event input is being filled with the empty "" (double quotations).

I think there should be a way to disable / enable parts of the library, or each feature should perhaps be available through its own library... so maybe an extra one called react-easy-storage? In my current use-case I'd be able to use that one and cut out the params side of things for now.


EDIT:

In actual fact, I kinda like what you're doing here:

key = encodeURIComponent(key)
value = encodeURIComponent(JSON.stringify(value))

and here:

const key = decodeURIComponent(keyValue[0])
const value = decodeURIComponent(keyValue[1])
try {
    params[key] = JSON.parse(value)
} catch (err) {
    params[key] = value
}

I guess that takes care of converting everything correctly and maintaining type information? I may just implement this in my current use-case as well, as I agree its quite nice to have that information. Then my code should be compatible - so its no biggy.

But perhaps still something to look into for people who do want to only opt in to a certain part of the library.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.