async / await with Polymer 2.0 - async-await

can we use async / await with Polymer 2.0 ?
https://developers.google.com/web/fundamentals/getting-started/primers/async-functions , As soon as I use it in my code it throws errors on hydrolysis / analysis. Any sample code will be helpful too if there is a any special guidance on this.
Regards,
S

I am also interested in the subject and from what I can understand now it is not supported out of the box. Async functions are part of ES2017 and are in Draft state now. So if you want to use it you should either use transpiler like Babel or use TypeScript. In either case you need to transpile async/await to ES6 or ES5. Polymer 2.0 is going to suport TypeScript at some point, but it does not support it yet.
Check out the tutorial on how you could integrate BabelJS Build an ES2015/ES6 app with the Polymer Starter Kit
When you have transpiler in place you can use async/await everywhere where promises are supported by Polymer.

Related

Avalonia + ReactiveUI - pharmacist for Events() generation

I'm trying to get my head around Avalonia in general, and the Reactive UI integration in particular. From googling around, I understand that Avalonia pulled away the Avalonia support in ReactiveUI, and tries to integrate ReactiveUI into Avalonia itself, to support a sometimes unstable Avalonia API.
I'm implementing a flow where a double tap on a DataGrid row should open a details windows, which I can do by adding a handler for the DoubleTapped event in the code behind. However, I was wondering if I could do this in a Reactive UI way, in a WhenActivated() implementation, by observing the DoubleTapped event.
In the ReactiveUI documentation, I see that there is a Pharmacist integration, which generates the observables for these events. However, when I fetch a reference to the DataGrid in the code behind, and try to hook into the DoubleTapped via
myDataGrid.Events(). ..., I don't get to see any events. Does this imply that there's no such support in Avalonia at this time?
Finally, while I'm at it, if I forget about the Reactive UI support, and use a straight-forward event handler, I need to do some stuff to detect whether it was a row that was double tapped, or something else (such as the header). I have to do this, because there's no EventSetter implementation in Avalonia as I understand it.
Somebody who knows if Avalonia will support this in the future?
Edit: in the end I used ReactiveUI somewhat similar to
TreeView.GetObservable(DoubleTappedEvent)
.Subscribe(async x =>
{
var selectedItem = TreeView.SelectedItem;
if (selectedItem is TreeNodeViewModel treeNodeViewModel)
{
await ViewModel!.ActivateResource(treeNodeViewModel);
}
}).DisposeWith(d);
An attached behaviour can also help to bind events to perform logic. There is a sample that looks like it could work provided the DoubleTappedEvent is being fired.
Avalonia Docs - Creating and binding Attached Properties
The dev tools should help show the event your are looking for tunnel and bubble though the DataGrid?
Pharmacist does not support Avalonia. They are working on ReactiveMarbles.ObservableEvents, which as of right now, doesn't work on generic classes, but they're working on fixing it.

Problems with i18next language detection and integration with hapi

I'm trying to write a new language detector plugin for i18next for integration with hapi. There's an existing hapi-i18next plugin that is quite old (it uses an extemely old version of i18next, 1.7.10 ) and so mostly useless. And the i18next API docs are pretty vague about how to write new plugins and exactly what the language detection process is. Does it run every time the t() function runs? should it be asynchronous? Has anybody else out there recently integrated hapi with i18next? I realize this is rather general but i'm not sure where else to turn.
Never used hapi so far, but seems hapi evolved a lot since version 8 (what's actually used here)
I don't know if that project is still maintained...
Perhaps you could try to create a new hapi-i18next plugin... (was not that much code)
To create a languageDetector plugin, it should not be a big thing... start here and continue by comparing how the express language detection works
In i18next the languageDetector is triggered here
...so on init/load and on a potential language change
I hope this helps.
What I ended up doing is writing a hapi server extension rather than a plugin, and a module that runs at startup that decorates the hapi server object with the initialized i18next object. The extension is installed to run onPreHandler and it basically clones the i18next object, attaches that instance to the request object, and detects the language (from the request header or from a query parameter), then sets the cloned instance to that language. This way, whenever a route handler uses the t() function attached to the instance that's attached to the current request, we know we'll be translating into the right language. Note that this is still for Hapi 16 (I need to port to 17/18 soon)...

Use pouchdb promise polifil

I'm using pouchdb as a library in a tiddlywiky project. It provides a common js compatible environment, so I can just require it.
My project is targeted to several browsers so I can't expect promises to be available as default. Since pouchdb uses promises extensively I tough that it will be simpler to use promises in the rest of my code. I know that pouch includes a promise polifil, so here is my question :
Is that polifil available from outside? Can I use it? How?
Thanks and regards
Yes, you can use PouchDB's promise polyfill by using pouchdb-promise: https://www.npmjs.com/package/pouchdb-promise
If you are using npm, then it's just require('pouchdb-promise'). Otherwise, you can get it from wzrd.in: https://wzrd.in/standalone/pouchdb-promise

Streaming json in nativescript

has anyone used the streaming json in nativescript? I found this http://oboejs.com/why but it seems not to work. I'm using nativescript 1.6, any suggestion would be appreciated really much. Thank you.
There is no library to my knowledge currently built for NativeScript that allows streaming JSON. Just for clarification sake you can easily pull JSON from a server and parse it using the built in fetch/http api's, right now -- but their is no way to have it start parsing the json as it downloads in chunks built in.
You can attempt to modify the npm node module to build for NativeScript.
Or thinking outside the box a bit; you can also use the web based version of that module inside the nativescript-webworkers and have it pull and process your JSON and communicate the json messages back to the NS environment. The WebWorkers module actually wraps the native platform's web browser module so it can run all browser based JS code.
Disclaimer: I'm the author of the open source NativeScript-WebWorkers.

Modernizer conditional load of polyfill

I am using a javascript library that uses CustomEvent that doesnt seem to be fully supported in Android 4.1. So I thought I'd use Modernizer to conditionally load a CustomEvent polyfill in browsers where it is missing.
I went here: https://modernizr.com/download?customevent-dontmin
Selected 'CustomeEvent',
Downloaded the suggested EventListner.js polyfill,
Pressed 'Build' and downloaded the custom Modernizer.
I added to my index.html: <script src="js/modernizr-custom.js"></script>
And added this to my javascript:
Modernizr.load({
test: Modernizr.customevent,
nope: 'EventListener.js'
});
But I get an error: TypeError: Modernizr.load is not a function
Can someone please confirm I've not gone completely off piste here and I'm using modernizer correctly? And do I have to download another script or something to get the Modernizer.load function? (Modernizer seems to have changed since similar questions were asked).
Modernizr.load was removed from Modernizr
Modernizr.load has been deprecated in favor of using yepnope.js directly; from v3.0, yepnope.js must be included in the page in order for Modernizr.load to work: calling .load() will simply pass the arguments on to yepnope(); this will be removed fully in a future release (#1241)

Resources