How to store something in JavaScript temporarily? - javascript

I am trying to create blackjack with JS and React.
So far I have got most of it working but my main problem is that everytime react renders it changes the cards and the order of the deck etc. I just need a simple way to store data and so even when react re renders it keeps the order of the deck (array of objects). I am use to firebase but that seems quite heavy for something like this. any ideas? i saw local storage might be an option too but wanted peoples opinions.

Related

How to serialize and restore vuex store state?

I´m using vuex for a very simple single purpose application. I would like to include a functionality that enables users to get a string(/url) that they can save to later recreate the store state.
For this, I thought it would be the easiest way to just dump the store state and later reinitialize the app with this dump.
Any idea how to achieve this?
I looked into the existing vuex persistence libraries but they seem to be overkill for what I´m aiming for. Simplicity beats sophistication in this scenario.
vuex persistance libraries I looked at
https://github.com/robinvdvleuten/vuex-persistedstate
https://github.com/championswimmer/vuex-persist
I got an answer in the Vue Discord chat:
"just JSON.stringify it"
Example: https://github.com/devCrossNet/chaptr/blob/master/src/app/home/Home/Home.vue#L118
Works like a charm.

React-Redux How to improve performance?

I am using the react-redux for one of my app, The design is quite difficult and performance required is very high. its actually wyswyg builder.
We have been using the react from last 2 months, Then we moved to the react-redux for the separation of code and improve maitainance, code readability and the parent-child approach headache ofc.
So, I have an array which has quite complex structure
This is how my state look a like:
const initialState = {
builder:{},
CurrentElementName:"",
CurrentSlideName:"",
.......
}
As redux recommend to have less data in particular object as possible, I have another 8-9 reducer which are divided from the main state.
My problem: builder object is very complex which has almost 3-4 levels down, objects and arrays, this all are managed runtime.
So, on the componentdidmount my application will call the server get the data and fill the builder:{}
builder:{
slidedata:[{index:0,controName:'button',....},{index:0,controName:'slide',....}],
currentSlideName:'slide1',
currentElementName:'button1'
}
This builder object is quite complex and depends on the user actions like drag and drop, changing the property, changing events, changing position this builder object is being changed by the reducer
let clonedState= JSON.parse(JSON.stringify(state));
//doing other operations
Every time some thing changes this object needs to perform certain complex operations, for ex, adding the new slide will do certain operations and add the slide to the current array called slidedata.
What is the best practice to fast this things up? am I doing something wrong?
I am not sure what is the wrong in this code, and as redux recommend I can not use the flat structure for this particular array as its managed run-time.
I am sure that component has the data which the component wants.
Is there any way to handle the big data? This iterations and changing the state is killing my performance.
Based on my current experience with React-Redux framework, Re-select and ImmutableJS make a perfect combination for your requirement.
Re-Select uses memoization technique on Javascript objects and have list of API's specifically dealing with these kind of large set of Javascript objects thus improving performance. Read the docs.
Note: One should wisely read the documentation before using this setup to churn the best of these tools.
You can either create your own boilerplate code using above libraries or use the one which i am currently using in my project.
https://www.reactboilerplate.com/
This boilerplate is specifically designed for performance. You can customize it based on your needs.
Hope this helps!

State container(like Redux) in angularjs?

I'm working in a big project which we develop a Dashboard that display the user lots of data in different ways, charts tables and more.
The user has the power to filter the data, add filter expressions, filter data from table and mutate it.
Sometimes i feel really like i need a state container that will manage all of this data because it really gets hard for me to debug a problem or adding a new feature.
I would like your advice about what state container to use with angularjs (1.4.8)?
And what are the best ways to implement it on a big written project?
I have worked on similar kind of work on which you are working on. I made a dashboard, which shows a lot of data using different plots( line, volcano, bar, heatmaps) and there was a way to interact all of them and filtering data and all.
For that purpose, I used angular-redux. Its very nice as at each interaction you can get your complete state object. That is managable and makes debugging very easier.
For that I followed angular-redux doc to make its configuration. Also, there is one chrome extension redux-devtools, which shows all of your actions and state after each action. That helps you to keep tract on your state model.
If you want more info on redux, there are some good doc, which you can read.
redux-basics(1) redux-basics(2)
By looking at your need, I would recommend you to use redux.
Hopefully this will be helpful for u. If you need any other info, Let me know

How can I improve the performance of passing around a large JSON object in React Native?

I'm building an app with React Native and on my transitions, where I'm loading more data, it's very slow and I'm wondering if there's a better way to structure my app to avoid these shutdowns, which get longer as the JSON file gets larger.
Let's say I have
var data = require('./data/data.json')
in my index view, I think pass this data to a view, which then splits it up to other views like items={data[section_name]} and it goes down recursively like that further down the hierarchy. Creating smaller dicts on each level. And even with small objects it is still quite slow.
The JSON files I'm working with are from 3-8 MBs.
I understand what you want do to with your big data in your project, because I did the same way before for my react-native app.
Actually, this way is fine, it's kind of loading the data once only, then we can retrieve hierarchy easily like items={data[section_name]}
However, the problem now is it may take a while for processing the big data!
Therefore, the idea is we should move the part of loading/initializing the data asynchronously, move it somewhere out of our view, so that the view's transition as well as its other things will not be affected! Then, when the data are being loaded/processed, we may show something like fade-in, fade-out effects, on the view, so it will take a short-time (300-1000ms). However, in my opinion, there may be a better way for this: when the application is opened for the first time, when the splash screen is being shown (for a few seconds, this behavior is common, we can load the big data in the background here!)
FYI, my application loads big data using ajax, it will even take longer than loading local files, but using my above-mentioned way, nobody complains about the data-loading speed ^^ (actually, users don't know and don't see where and when data are loaded, when the app goes to its home/top page, everything has been fully loaded)
Now it comes to the important part of my answer: I suggest you using Flux/Redux for this, maybe Flux is easier for you now, because Redux is kind of an improvement based on Flux (in either Flux or Redux, we will have a Store, and this Store will work asynchronously, you can store your big JSON data here):
https://www.atlassian.com/blog/software-teams/flux-architecture-step-by-step
Flux can be applied on reactjs and react-native of course, you may find there are several new definitions if you don't know about Flux or Redux yet, however, it's really worth reading and trying! After you understand it, it'll be very easy and then you can apply that architecture on whatever react project you like ^^

How to use values across Routes?

I have recently started to work on React, however I came across one issue. I have set up Routes, for different sites. Though in one of the classes, I have an Object, with given values. On the other hand, I have another class, where I want to fill out certain input fields with these values from the object. Is there a way, to use values across Routes?
You can store the data in a store if you are using Flux, or in a state if using Redux. If you can share some more information about your project, I might be able to help with it better.

Categories