medialize / medialize/jQuery-store

Initializing $.store twice adds duplicate en/decoders

Open
#5 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
70
Forks
14
PR merge metrics
No merged PRs in 30d

Description

Running the following code:

```
s = new $.store();
s.set('test', {"a":1});
console.log('Get 1', s.get('test'));
s = new $.store();
console.log('Get 2', s.get('test'));
```

results in

```
Get 1 Object
a: 1
SyntaxError: Unexpected token o
```

This happens because .encoders and .decoders are part of the prototype, and thus globally modified every time `new $.store` is called.

This is an issue because I am using this in a single page application, and use it in just one model where it's needed (instead of storing a global reference and only initializing once).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the $.store constructor and inspect how the prototype-level .encoders and .decoders are initialized; reproduce the provided two-instance example first. Done means creating a second store does not duplicate registrations, and both get calls complete without the reported SyntaxError.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.