Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
ApproachingInfinity
Sep 14, 2008

Dominoes posted:

VSCode's complaining about comment sin a `manifest.json` file I'm working on.

I just changed my user prefs so that VSCode treats all .json files as “jsonc” (“JSON with comments”); at work we use json as a mix of config and game data, and not having comments for all that sucks. I’ve never seen any parser that cared even a little about comments, even if it is against the spec.

It still does have dumb stuff like “no trailing commas ever :saddowns: “, but those at least appear as just warnings.

Adbot
ADBOT LOVES YOU

Dominoes
Sep 20, 2007

Thanks for that tip on disabling the inspection. The no-trailing-commas things aumsing, in that the default formatter for a diff language I use adds them!

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Dominoes posted:

Thanks for that tip on disabling the inspection. The no-trailing-commas things aumsing, in that the default formatter for a diff language I use adds them!

That's because trailing commas is the right thing to do and JSON rarely does the right thing.

Jaded Burnout
Jul 10, 2004


Thermopyle posted:

That's because trailing commas is the right thing to do and JSON rarely does the right thing.

I got voted down on this 2 to 1, RIP my git blame.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Jaded Burnout posted:

I got voted down on this 2 to 1, RIP my git blame.

you work with monsters

FormatAmerica
Jun 3, 2005
Grimey Drawer

Thermopyle posted:

you work with monsters

Who hate clean commit diffs

smackfu
Jun 7, 2004

Once I looked into how eslint supports comments in their JSON and they just use a package that strips them out first and then handle the resulting JSON normally, so that was exactly what I should have expected.

fsif
Jul 18, 2003

FormatAmerica posted:

Who hate clean commit diffs

An extra green line you see for three seconds when merging a PR versus a lifetime of maddening, incomplete sentence rear end syntax.

Dominoes
Sep 20, 2007

I've loving had it with moment. I did what you're never supposed to do and built a (limited scope to what I need it for; don't need to worry about the usual localization/DST pitfalls) Date / DateTime module for a big webapp I have, and in addition to the expected traps being gone, the app is dramatically faster and more responsive.

I'm suspicious if I could completely remove it the bundle size would drop, but I'm using a third party Date Picker that relies on it.

Sagacity
May 2, 2003
Hopefully my epitaph will be funnier than my custom title.
How many dates were you shown for it to be a dramatic change?

gbut
Mar 28, 2008

😤I put the UN🇺🇳 in 🎊FUN🎉


I'm _this_ close to initiating a ban on moment at my work.

If I can't trust you to use Vuex properly, and you end up with a action chains that take me back to old-timey callback hells, why should I trust your choice to use moment.js?
No, Jerry. You don't need the ability to calculate time spans with consideration of Rio de Janeiro summer time in November of 1963, just so the customer can enter their loving birth date.

Moment.js is a cancer. If you are not doing something specifically related to tricky time conversions, you should be able to rely on browser localizations. They've gotten pretty good by now.

And for the love of all that is good, use UTC when storing it. Don't let the DB do more transformations. You know what they say: when you fiddle with the data, you can only lose information, not add to it.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Lazy man's solution to moment issues: Compile a sane datetime library from a sane language to webassembly and use that.

Dominoes
Sep 20, 2007

Sagacity posted:

How many dates were you shown for it to be a dramatic change?
A lot. It's a scheduling app.

Thermopyle posted:

Lazy man's solution to moment issues: Compile a sane datetime library from a sane language to webassembly and use that.
The app in question has two other parts. Python: The standard DT library is pretty good. I just wrapped it lightly to force TZ-awareness and improve the API. Rust/WASM: This is what you're implying - Chrono is very well designed. The API's verbose, but it's rock-solid in terms of doing what you expect. Has everything Moment's bad at: sep date/time/dt/naivedt/naivetime that don't interact without calling explicit methods, no surprise mutations, strict type adherance, consistent API etc.

Dominoes fucked around with this message at 19:24 on Dec 28, 2019

Jaded Burnout
Jul 10, 2004


fsif posted:

An extra green line you see for three seconds when merging a PR versus a lifetime of maddening, incomplete sentence rear end syntax.

You're missing the point. it's not about the extra line change during the PR review (though that is annoying), it's that if you have a list of 3 things and add one, you have to change line 3, which means that looking at git blame for line 3 now brings up the useless information that you added line 4, rather than the more useful information of e.g. why line 3 was added or modified in the past.

Any syntax you can get used to, but actively making our tools less effective sucks.

Also, the whole point of using trailing commas is when you have things on multiple lines for exactly this reason, so "incomplete sentence syntax" is a wacky thing to say since
most people,
don't write sentences,
like this.

Dominoes
Sep 20, 2007

While I'm chucking spears at Moment, I'm obliged to point out that its string formatting tokens are the nicest I've see, ie compared to the usual `%`. I stole it for the Python wrapper I mentioned.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Dominoes posted:

A lot. It's a scheduling app.

The app in question has two other parts. Python: The standard DT library is pretty good. I just wrapped it lightly to force TZ-awareness and improve the API. Rust/WASM: This is what you're implying - Chrono is very well designed. The API's verbose, but it's rock-solid in terms of doing what you expect. Has everything Moment's bad at: sep date/time/dt/naivedt/naivetime that don't interact without calling explicit methods, no surprise mutations, strict type adherance, consistent API etc.

Yeah, chrono is what I had in mind when I made that post. It's pretty good.

Go compile it to webass, wrap in some JS, release it to the world, and become super famous.

Or maybe complie it to asm.js and then you can put it on NPM. Or maybe you can do that with wasm? I can't really think through it right now.

The Merkinman
Apr 22, 2007

I sell only quality merkins. What is a merkin you ask? Why, it's a wig for your genitals!
What's wrong with moment now? Is Luxon ok?

Dominoes
Sep 20, 2007

Thermopyle posted:

Yeah, chrono is what I had in mind when I made that post. It's pretty good.

Go compile it to webass, wrap in some JS, release it to the world, and become super famous.

Or maybe complie it to asm.js and then you can put it on NPM. Or maybe you can do that with wasm? I can't really think through it right now.
I think wasm-bindgen would make this straightfwd to compile as a WASM module. I'm suspicious it would involve a good deal of tedium to wrap the inputs/outputs of each structure and function. Would work best with Typescript so you can maintain the type safety between the various types of dates/times. I think bindgen has this type of support built-in, ie generating TS types.

The Merkinman posted:

What's wrong with moment now? Is Luxon ok?
Summary in my last post showing a contrast: " sep date/time/dt/naivedt/naivetime that don't interact without calling explicit methods, no surprise mutations, strict type adherance, consistent API etc.", plus the speed issue, which will bite if you use many DTs or calcs on them. And it tries to be clever with parsing, and you may not know if it succeeded until your app does the wrong thing. Overall: It only has one type that it tries to coerce into many different actions, and it's not obvious which functions mutate data vice returning something new. You have to be very careful it's doing what you expect. Ie with Chrono, it won't compile if you try to do something dumb, and you have to specify the types and TZs involved, so you can usually tell beforehand. Other bonuses along the same vein are using enums instead of integers for weekdays etc. Ie You test for a Monday like == Weekday::Monday instead of trying to remember what the integer for it is. (0 or 1?)

I can't speak to Luxon.

Dominoes fucked around with this message at 22:29 on Dec 28, 2019

Dominoes
Sep 20, 2007

I'm taking a crack at it. Related Q that came up for another reason. Is it possible to make constructor methods besides the default constructor / New()? I seem only able to call methods on instances, and make constructors from standalone fns.

MrMoo
Sep 14, 2000

The Merkinman posted:

What's wrong with moment now? Is Luxon ok?

I use this, recommended here by someone before. It works, kind of annoying to inspect a value when debugging is about my only gripe. It is spawned from the Moment team.

Dominoes
Sep 20, 2007

How can I export functions that aren't active until a promise completes. Ie for the affirmationed WASM wrapper:

JavaScript code:
let r
rust.then(m => {
r = m
    console.log( m.from_ymd(1999, 2, 1), "RESULT")
})
.catch(console.error);

export function from_ymd(year: number, month: number, day: number): NaiveDate {
    return r.from_ymd(year, month, day)
}
I want to expose the `from_ymd` function as a normal JS module. The call in the promise at the top works, but calling the bottom one doesn't. I'm probably doing something wrong with promises.

marumaru
May 20, 2013



The Merkinman posted:

What's wrong with moment now? Is Luxon ok?

hadn't heard of luxon, but dayjs just works(tm) in my experience.

fsif
Jul 18, 2003

Jaded Burnout posted:

You're missing the point. it's not about the extra line change during the PR review (though that is annoying), it's that if you have a list of 3 things and add one, you have to change line 3, which means that looking at git blame for line 3 now brings up the useless information that you added line 4, rather than the more useful information of e.g. why line 3 was added or modified in the past.

Any syntax you can get used to, but actively making our tools less effective sucks.

Also, the whole point of using trailing commas is when you have things on multiple lines for exactly this reason, so "incomplete sentence syntax" is a wacky thing to say since
most people,
don't write sentences,
like this.

What do you do if you add new imports from a module and Prettier moves the imports to multiple lines?

Your workflow might differ from mine, but I don't spend all that much time comparing past commits. When I do, an added comma has never made my tooling less effective. It's always been pretty easy to infer what's going on.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
No-one gives a poo poo about auto-organized imports because no-one gives a poo poo about figuring out when or why a particular import was added.

Perhaps you can figure out why people might care more about identifying the origin of changes to actual code.

fsif
Jul 18, 2003

I mean a guy that hyphenates "no one" probably isn't going to relate to my particular syntactical preferences.

teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself

Dominoes posted:

How can I export functions that aren't active until a promise completes. Ie for the affirmationed WASM wrapper:

JavaScript code:
let r
rust.then(m => {
r = m
    console.log( m.from_ymd(1999, 2, 1), "RESULT")
})
.catch(console.error);

export function from_ymd(year: number, month: number, day: number): NaiveDate {
    return r.from_ymd(year, month, day)
}
I want to expose the `from_ymd` function as a normal JS module. The call in the promise at the top works, but calling the bottom one doesn't. I'm probably doing something wrong with promises.

This isn't really how promises work. Is the function that's being returned from the promise defined in your codebase? And is it synchronous?

Dominoes
Sep 20, 2007

The promise starts firing when we load that JS file, and completes when the WASM module is loaded. I can call the WASM functions inside that promise loop, but that precludes wrapping and exporting them.

The function being returned in the promise is a Rust function compiled to WASM. Ie, the function being returned is this:

Rust code:
#[wasm_bindgen]
pub fn from_ymd(year: i32, month: u32, day: u32) -> String {
    NaiveDate::from_ymd(year, month, day).format("%Y-%m-%d").to_string()
}
I'm only able to call it from within the promise scope, but I want to export it so someone can call that JS file as a module, and call the rust fn as if it were a normal JS fn. This is a bit of a specialized use case, but there's a good chance the problem is just me not knowing how promises/async works.

Dominoes fucked around with this message at 04:55 on Dec 29, 2019

M31
Jun 12, 2012
Or use date-fns: https://date-fns.org/

You could also try the new JS API, which is still in active development, but probably still more sane than trying to import the Rust api:

https://github.com/tc39/proposal-temporal

Dominoes
Sep 20, 2007

M31 posted:

You could also try the new JS API, which is still in active development, but probably still more sane than trying to import the Rust api:

https://github.com/tc39/proposal-temporal
That looks neat! This is probably a dumb project since it would take a lot of work to wrap the whole API; ie I think once I got over that async hurdle, would have to wrap each function etc on both the Rust and JS side. (Rust to wrap with bindgen, JS to define Classes etc with similar fields and methods) I'm still curious if this type of thing is feasible, since it has broader applicability.

Step 1 can be looked at as converting the module to WASM; easy. Step 2 is wrapping it in a JS module that lets JS users transparently call the WASM as if it were a normal JS module. That's what I'm stuck on. Ie get the code out of the promise and into the global namespace.

Here's a SO post describing it; accepted response is that's not how promises work, but there has to be a way around this; the async code here's a side-effect, not the point. It takes on the order of ms to complete. (Subtle distinction that may or may not matter; I want to take functions and classes out of the promise vice a normal value)

edit: Got it working with code to this effect:
JavaScript code:
const rust = import('../pkg');

export let loaded = false
export let from_ymd: Function

rust.then(m => {
    from_ymd = (year: number, month: number, day: number): NaiveDate => {
        return m.from_ymd(year, month, day)
    }

    loaded = true
})
.catch(console.error);


export class NaiveDate {
    // ymdf: DateImpl
    year: number
    month: number
    day: number    
}

Dominoes fucked around with this message at 19:22 on Dec 29, 2019

Met48
Mar 15, 2009
That async loading looks like it's from a dynamic import, does an import statement work?

JavaScript code:
import * as rust from '../pkg';

console.log(rust.from_ymd(1999, 2, 1), 'RESULT');
Also, the custom JS may be unnecessary. wasm-bindgen can generate JS classes for Rust structs, methods from impl blocks, getters and setters for pub fields, etc.

Met48 fucked around with this message at 09:30 on Dec 30, 2019

Dominoes
Sep 20, 2007

That would be fantastic. Here's the error I get when I try using import * as chrono from "../pkg"

JavaScript code:
ERROR in ../pkg/chrono_js_bg.wasm
WebAssembly module is included in initial chunk.
This is not allowed, because WebAssembly download and compilation must happen asynchronous.
Add an async splitpoint (i. e. import()) somewhere between your entrypoint and the WebAssembly module:
No immediate solutions are coming up. There might be a way to configure webpack to make this work.

Dominoes
Sep 20, 2007

From the top of the Luxon homepage: features DateTime, Duration, and Interval types. No, not OK. Needs Date and Time types as well.

Secx
Mar 1, 2003


Hippopotamus retardus
I'm looking for an example of a Single Page Application web form that dynamically loads the questions/fields based on what is answered. An example would be a bank loan application where you select what kind of loan you're looking for (mortgage, car loan). Depending on what you answer, additional questions are dynamically loaded in via ajax.

I have an idea for a Chrome extension, but I need an example of a SPA web form like the above to build a proof of concept/do testing/research without building one myself.

teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself

Secx posted:

I'm looking for an example of a Single Page Application web form that dynamically loads the questions/fields based on what is answered. An example would be a bank loan application where you select what kind of loan you're looking for (mortgage, car loan). Depending on what you answer, additional questions are dynamically loaded in via ajax.

I have an idea for a Chrome extension, but I need an example of a SPA web form like the above to build a proof of concept/do testing/research without building one myself.

Turbotax maybe?

Dominoes
Sep 20, 2007

Secx posted:

I'm looking for an example of a Single Page Application web form that dynamically loads the questions/fields based on what is answered. An example would be a bank loan application where you select what kind of loan you're looking for (mortgage, car loan). Depending on what you answer, additional questions are dynamically loaded in via ajax.

I have an idea for a Chrome extension, but I need an example of a SPA web form like the above to build a proof of concept/do testing/research without building one myself.
Can you be more specific? This sounds trivial t make in any declarative framework.

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

Dominoes posted:

From the top of the Luxon homepage: features DateTime, Duration, and Interval types. No, not OK. Needs Date and Time types as well.

I'm not sure where you draw the distinction between a Date type and a DateTime type without consideration for time and a Time type and a DateTime type without consideration for date.

Seems like you're trying to solve this with wasm and drat any other solution that might be easier.

Dominoes
Sep 20, 2007

There are many cases for wanting a date with no time data and vice versa. I don't think this is an unpopular or controversial opinion, given most DateTime libraries make the distinction, including the upcoming one for JS posted earlier in this thread.

How do I iterate over days without a datetime type? The JS-Date / moment solution appears to be be by iterating through datetimes with time set to midnight, but this is awkward, and in those two libs, is a source of several categories of subtle error.

Dominoes fucked around with this message at 21:41 on Jan 1, 2020

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Dominoes posted:

There are many cases for wanting a date with no time data and vice versa. I don't think this is an unpopular or controversial opinion, given most DateTime libraries make the distinction, including the upcoming one for JS posted earlier in this thread.

How do I iterate over days without a datetime type? The JS-Date / moment solution appears to be be by iterating through dates with time set to midnight, but this is awkward, and in those two libs, is a source of several categories of subtle error.

Yeah, dates without time and times without dates are pretty important things to have to accurately model the things people want to model.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Dominoes posted:

There are many cases for wanting a date with no time data and vice versa. I don't think this is an unpopular or controversial opinion, given most DateTime libraries make the distinction, including the upcoming one for JS posted earlier in this thread.

How do I iterate over days without a datetime type? The JS-Date / moment solution appears to be be by iterating through datetimes with time set to midnight, but this is awkward, and in those two libs, is a source of several categories of subtle error.

You didn't really answer his question. I can see why "time without date" would be useful for recurring events and so on, but when does having a date with time set to midnight create an issue? Especially since without it, you're going to have no way to accurately handle timezone conversion, unless you eventually end up assuming midnight anyway and you're back to where you started.

Adbot
ADBOT LOVES YOU

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

One example that I most recently encountered is that when you are born is sometimes best represented as a date without a time component.

People mostly don't care about what time you were born, and people mostly don't care about converting the date based upon timezones. If you have time and tz info on the date you risk actually converting the date.

You could just use a tuple of ints for this but then you can't use functions for adding days/months/years to a date.

The problem with using a DateTime when you really want a Date is that you are now using convention rather than types.

Thermopyle fucked around with this message at 22:57 on Jan 1, 2020

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply