This post talks about how React components perform updates for different types of events and how
we can get these updates to behave in a way that is ideal when using AJAX actions that update multiple Flux stores.
React components will batch their updates inside of Events.
This means that when a component's setState function is called
multiple times inside of an OnClick event, the component will only call render once (if shouldComponentUpdate returns true).
This is exactly the behavior I want. I only want to interact with stores that are in a complete, stable, and ready state.
AJAX and timeout events
Unfortunately, AJAX and window.timeout events are not batched like SyntheticEvents.
It is common for my code to update multiple stores from a single AJAX response.
Bugs crop up by using the default behavior of re-rendering on each call to setState.
Luckily, there is a pattern to batch these updates and it is pretty simple to do to.
I batch the updates by using a single store that sets a isLoading boolean
at the beginning of the AJAX event call and doesn't clear it until all the stores have finished their updates.
The main react component will use this
isLoading boolean inside of its shouldComponentUpdate function. The logic will say to not update if the current state and the next
state is loading.
This isLoading acts as a lock and batches all the stores updates into one single render call.
This holds the invariant in our components that stores will be in a complete and stable state during render calls.
UI Lock Example
Here is a partially implemented version of a loading lock that performs batch updates for AJAX events.
Encrypting secrets with knife-solo
Wednesday, October 21st 2015
We've had some secrets laying around in our database that needed to be changed and encrypted.
We have been using chef to deploy our service. With chef data bags we can encrypt and decrypt our secrets.
There is one problem though. It expects you to have a chef server.
However, we are using a pretty simple setup with no chef server at the moment.
Luckily there is knife-solo and knife-solo_data_bag.
Create a data bag named secrets with an item named database
Edit the existing data bag item.
Logging django apps to syslog
Wednesday, May 25th 2015
I spent most of my day filling in the holes of my django/python logging knowledge.
I've never done logging in python or a django app before. And thus our code base, had zero logging in it.
A huge problem when it comes time to debug issues in production.
I read a few articles that I found at Full Stack Python and
also went through the Python doc logging tutorials.
Taking Some Pain out of Python Logging
was an eye opener when Hynek explained that syslog
can capture and record the python log records. Syslog was exactly
what I set out to do (I didn't know it was called syslog. I just knew about /var/logs, so today was a good learning experience).
I am not doing exactly what Hynek does. But it accomplishes my goal of getting our logs into syslog.
Here is the final LOGGING dictionary in settings.py I went with.
& ~ # This stops local7.* from going anywhere else.
Do a sudo service rsyslog restart so rsyslog.d can pickup the new config. And ta-da!
May 28 03:19:57 vagrant 11874 140156620121856 thingsforwork.dashboard.views.home DEBUG we are in the home page, this is a debug
May 28 03:19:57 vagrant 11874 140156620121856 thingsforwork.dashboard.views.home INFO We are logging django! e01be3ae-e9d1-49d7-97ac-00c5454f3026
May 28 03:20:02 vagrant 11874 140156620121856 requests.packages.urllib3.connectionpool INFO Starting new HTTP connection (1): dashboard.reviewpush.com
May 28 03:20:02 vagrant 11874 140156605413120 requests.packages.urllib3.connectionpool INFO Starting new HTTPS connection (1): tartan.plaid.com
May 28 03:20:02 vagrant 11874 140156392699648 googleapiclient.discovery INFO URL being requested: GET https://www.googleapis.com/discovery/v1/apis/analytics/v3/rest
May 28 03:20:02 vagrant 11874 140156375914240 requests.packages.urllib3.connectionpool INFO Starting new HTTPS connection (1): quickbooks.api.intuit.com
I write about computers, software development and other topics that interest me.
I live in the Seattle, WA area.
I'm currently employeed as a software engineer at Amazon.