> But with LV wouldn't you need to create both a LV and a regular controller? That's a huge amount of code duplication.
You just do LiveView instead of a regular controller. No duplication.
When you request a page, it is render on the server and all of the HTML is returned over HTTP as usual.
After the client has received the HTML updates, live updates can go over a websocket. For instance you start typing in a search field, this is sent to the server over websockets. Then the server might have a template for that page that adds search suggestions in a list under that search field. The server basically automatically figures out how the page should be rendered on the server side with the suggestions showing. By "re-rendering" the template with changed data used with the server side template. Then it sends back a diff to the client over websockets. The diff adds/changes the search suggestions to the page. The diff is very small and it's all very fast.
> You just do LiveView instead of a regular controller. No duplication.
Yes but this is only in the happy case when the client is fully enhanced no?
What happens if you hook up a phx click event to increment a like counter.
After the page is loaded, if you click the + to increment it while having JavaScript disabled it's not going to do anything right?
But with Hotwire Turbo, if you have a degraded client with no JS, clicking the + would result in a full page reload and the increment would still happen. That's progressive enhancement. It works because it's a regular link and if no JS intercepts it, it continues through as a normal HTTP request.
Yes, the `phx-click` doesn't automatically get translated to a link or form submission. You can still design the page to work without javascript. For instance by having a "+" button be a normal form or link and then have phx-click intercept it when javascript is enabled. This can be done with one LiveView module without having to also have a separate regular controller.
One way to do it would be to in the `mount` function handle normal non-javascript params being sent and a `handle_event` function handle `phx-click`.
I don't know if there is already a way to have `phx-click` with fallback to HTTP in a less "manual" way. It should be possible to make.
I've found that the vast majority of clicky stuff I do leads to a URL change anyways, and these are just proper links to the new URL that LV then intercepts.
In your Counter example, it's true that for the 'degraded' version to work, the link would have to be a proper link and not a phx-click. But in the (IMO very unlikely) case where this fallback is necessary, solving it with a proper link/route does not require duplication, just a different approach.
What you would do is create a LiveView that handles both the initial page and the 'increment' route. If LV is 'on', it intercepts the click and patches the page. if LV is 'off', your browser would request the 'increment' route, and the same LV would handle all this server-side and still display the new, incremented counter.
The LV is both the server-side controller /and/ the client-side logic. That's part of what makes it so appealing, but, admittedly, also something that can take a while to wrap your head around.
I've more than once reflexively gone for phx-click solutions where the LV would receive the event and 'do' something, only to later realize that it would be much better to use a proper url/routing solution (where LV is still the 'controller'). In hindsight it's often a case of treating LiveView too much like just 'React on the server', basically.
Supply of housing can increase if it makes sense to build housing. Zoning and other regulation can make it impossible, risky or unprofitable to build housing.
In Denmark you can get milk at the grocery store that was inside the cow less than 24 hours ago. Ultra High Temperature pasteurization is not really normal in Denmark, but I think it is in Germany.
I miss UHT and homogenized milk since I moved to Denmark :( I loved being able to buy a six pack of milk bottles back in France and keep it in a closet for weeks, now I can barely drink a carton of milk before it goes bad.
While most milk in Netherland is pateurised and therefore keeps only a few days, there's also sterilised milks which keeps for months. Doesn't taste as good, though.
In general people in Denmark don't have a ton of money to invest after paying taxes. If they do invest in Danish companies, those companies are held back somewhat by rules and further taxes. Some years ago there was a "entrepreneur tax" in Denmark which was an extra tax that affected business angels.
Employees could also be required to pay taxes on employee stocks - money that they had not earned yet because they had not sold them.
It is? I'm pretty ignorant with stocks so please excuse the stupid questions but I thought you weren't taxed until after selling them. Is that not the case? How does it work?
If you exercise stock options, you get taxed on the difference between the strike price and the market value at the time you exercise, as normal income (not capital gains).
This can be a big problem if you exercise stock options, then the price of the stock drops. You might not be able to sell the stock for enough to pay the taxes you owe, and although you can take a capital loss, you can't use capital losses to offset normal income (beyond a fairly small limit each year).
The same is true if you are given actual stock. You owe taxes when it vests (or hypothetically when you are given it if it is unrestricted stock) not when you sell it.
That just moves the point where you have to lay out money to even earlier. That's great if it's an early stage startup where the shares are worth practically nothing, but it's even worse if they are already worth a lot.
Oh sure; but you won't have to lay down any money until you sell your stock; and paying taxes on real money is a lot easier than paying taxes on imaginary money.
That's only true for NQ options. With ISO options you aren't taxed until you actually sell the shares they covert to, and then as a capital gain tax, not as ordinary income.
That's not true, the ISO option spread at exercise is taxed via AMT [1]. In general you shouldn't give out tax advice, and if you do at least make sure you have your facts straight. Plenty of early employees have been bitten by this rule and it doesn't that people perpetuate incorrect information.
That's only true when the value of your options is pretty small. ISOs are taxed under the AMT plan as regular income at a rate of 26-28%, and so you might be forced to pay taxes on them anyways.
Source: I had a fat AMT tax bill precisely because of this. :/
The taxation structures around stock options in the United States appear extremely complex. Google for something like "taxation of stock options in private company"...
I'm certainly not an expert, so don't listen to me for any financial or legal advice.
When you receive something of value from your employer, it generally counts as taxable income. This includes grants of stock or other perks such as a housing allowance or a car.
Like most Bay Area tech workers, I'm compensated partially in stock. Every month, X shares of my restricted stock "vest", which means, in practical terms, that I receive those shares. That counts as taxable income at the current market value of those shares. To avoid making me pay a large tax bill come April, my employer actually withholds some of those shares of stock to cover the tax bill.
(I've never been entirely sure how this stock-withholding works from a tax perspective. Do they immediately sell those shares and pay the proceeds to the government along with the rest of my income tax withholding?)
> To avoid making me pay a large tax bill come April, my employer actually withholds some of those shares of stock to cover the tax bill.
I think that your employer actually sells just enough of those shares at the time of vesting to cover the taxes. Any cash remaining difference is given to you in your next paycheck (i.e. 2 shares at $100 ea. are sold to cover $120 of taxes, and $80 is given to you). Could be wrong though.
You also get taxed when exercising options even if you don't immediately sell the shares you just bought. Something like the difference between the strike price and the current value being treated as income you earn upon exercising the options, so it's taxable.
True, but doesn't Denmark have big tax exemptions for investments you make through retirement accounts (which are limited in withdrawals until you're older)?
Of course, that probably wouldn't apply to non-public investments, and the caps are two low to be usable by Dane angels (far from home in the Bay especially).