
WinJS: The Windows Library for JavaScript - axelfontaine
https://dev.windows.com/en-us/develop/winjs
======
jasim
Here's a code snippet from the website:

    
    
        <div class="listView win-selectionstylefilled"
             data-win-control="WinJS.UI.ListView"
             data-win-options="{
                        itemDataSource: Sample.ListView.data.dataSource,
                        itemTemplate: select('.smallListIconTextTemplate'),
                        header: select('.header'),
                        selectionMode: 'none',
                        tapBehavior: 'none',
                        layout: { type: WinJS.UI.ListLayout }
                }">
        </div>
    

The ListView control looks quite powerful, but unfortunately that power comes
at the cost of learning a new templating language and all its quirks. Where is
the `select` method defined? Is it user accessible Javascript, or is it hidden
deep inside the library? What if I wanted to capitalize my headers - would
`data-win-options` evaluate Javascript? If it does, what is its binding? Does
it use a custom expression parser? If so, what are its quirks? How do I create
a reusable component out of this? How would I parameterize it?

There are a few custom tags here: 'data-win-control', 'data-win-options' and
'data-win-bind'. How many others are there, and how much time would I have to
spend in their API docs to grok them?

Having worked with ERB, HAML, and Angular extensively, and after dabbling with
Mustache, and thus relearning a different way to do the same thing over and
over, it has become apparent to me that templating languages ought to do
string interpolation and stop at that and leave the programming part to a
programming language.

------
sudioStudio64
The thing they are doing in 10 where you can publish a regular website in the
store is pretty cool, though.

You include some js and a manifest and your site detects if it's running in a
store container and gives you access to the device...camera, disk, tpm. That's
pretty cool.

I wonder how secure something like that can ever be...but its a neat idea.

~~~
asyncwords
For those that are curious about this, sudioStudio64 is talking about "Project
Westminster", which is one of the four "Universal Windows Platform bridges".
The other three let you essentially port Android, iOS and Win32 apps to the
new UWP platform and app store.

[https://dev.windows.com/en-us/uwp-bridges](https://dev.windows.com/en-us/uwp-
bridges)

~~~
sudioStudio64
Ahhh. Thanks! Very cool of you to drop the link!

------
OldSchoolJohnny
Why do so many links on HN to new tech go to a page that doesn't fundamentally
explain what it is right at the top?

What is this? Is it a way to access the windows api from javascript? Is it a
library of web UI components like Telerik?

So many projects seem to suffer from this same problem, just say what you are
doing in clear unambiguous short sentences right at the top with an example or
a picture and the world would be a much better place.

~~~
smacktoward
You may have to scroll a little, but under "Advantages of WinJS" it has a
decent description:

 _Use WinJS to build first class apps with HTML, CSS, and JavaScript. You can
use WinJS not only for your Universal Windows apps using HTML /JS, but also
for your websites, and when using HTML-based app technologies like Apache
Cordova. WinJS provides high quality infrastructure like page controls,
promises, and data-binding; polished UI features like virtualizing
collections; and high performance Windows controls such as ListView, FlipView,
and Semantic Zoom. This is a comprehensive toolkit for you to use with
confidence in its performance and polish, whether as a standalone solution or
with other frameworks and libraries._

~~~
Roboprog
So.... (marketing speak) HTML/CSS/Javascript ... make view component thingies
...

???

~~~
Roboprog
OK, down-voters: what _do_ all of those MS buzzwords mean???

------
mc_hammer
what i would have loved 10 years ago was a jquery for windows,
$('#32770').find('OK').click().. not sure if thats relevant still

anyway on win JS, have an upvote, but my advice is to stop extending html into
some javascript/xml hybrid.

i think a functional approach there would be really sweet

    
    
        <div data-ref="listview1">
          <button>1</button>
          <button>2</button>
          ........
        </div>
        
        winJS('listview1').all('button').onclick(dostuff)
        

lets extract the logic from the view, so its way more easy to maintain than

    
    
        <div class="button-well">
                    <button data-win-bind="onclick: changeSelectionMode">ReadOnly</button>
                    <button data-win-bind="onclick: changeSelectionMode">Single</button>
                    <button data-win-bind="onclick: changeSelectionMode">Extended</button>
                    <button data-win-bind="onclick: changeSelectionMode">Multi</button>
                </div>
    

also when you create a control on the fly you can see the difference in
keystrokes:

    
    
         $('body').append('<button>').onclick(dostuff)
         //versus
         body.innerHTML += '<button data-win-bind="onclick: changeslelectionmode">'; initBinds();
    
    

can you actually make native controls in win10 or windows mobile with this?
that would be really cool also.

~~~
pp19dd
The jQuery for windows that I found to have worked is AutoHotKey. But the
syntax is something out of a morse code book:

    
    
        #IfWinActive ahk_class LWJGL
        {
            *^=::
            {
                SendInput t
                Sleep 150
                SendInput %macro1%{enter}
                return
            }
        }
    

This sends commands to a minecraft window (LWJGL is somehow what windows
sees.)

~~~
chadzawistowski
I find AutoIt's BASIC-like syntax is a little nicer for complex tasks than
AutoHotKey, although AutoItX (usable from C++, VB, C#, F#, and other managed
languages) is the nicest to use of all.

------
mako-taco
I went to the 'try it out' page here
[http://try.buildwinjs.com/#listviewinteractions](http://try.buildwinjs.com/#listviewinteractions)

and noticed a ton of jank while scrolling. A quick look at chrome's timeline
reveals a nasty listener leak. Hopefully, it's user error and not a flaw in
the library.

------
Nemcue
Gah. I thought this was a library to do Automation in Windows using
Javascript. That would have been a dream compared to what the Windows
ecosystem currently has.

Autohotkey et.al are impressive in terms of functionality, but holy hell is
the syntax and structure awful.

~~~
Aleman360
[http://uiautomation.codeplex.com/](http://uiautomation.codeplex.com/)

Let's you do UI automation in PowerShell. This example starts calc.exe and
clicks buttons 1, 2, 3:

    
    
        Start-Process calc -PassThru | Get-UIAWindow | Get-UIAButton -Name [1-3] | Invoke-UIAButtonClick;

~~~
nextw33k
My problem with PowerShell is that its Yet Another Syntax To Learn (YASTL).

If a JavaScript runtime like nodejs had access to the same interfaces as
PowerShell or to COM I'd be over the moon.

It would be very powerful, you'd effectively be opening up windows shell
programming (OS scripting) to tens of millions of developers rather than the
1% that take the time to learn PowerShell.

~~~
Nemcue
Yes! You're so right.

I've actually experienced this first hand. There's a small but prolific
community on OSX who do this for Window Management and Automation; see
[https://github.com/jasonm23/phoenix](https://github.com/jasonm23/phoenix) and
[http://hammerspoon.org](http://hammerspoon.org)

They're _great_ to work with, and it's easy to build your own abstractions on
top since they actually have a real language that you can work with. Imagine
this for instance:

    
    
      Windows.find(window => window.title == "Sublime Text")
             .moveTo(Screen.find(screen => screen.name.contains("Dell"))
    

It's so bizarre to me this isn't a thing in Windows. It's a super good thing
to have.

------
megaman22
Cool, I guess. I'm not sure I see any point in writing native windows apps in
Javascript when you've got a much better language in C#.

~~~
benaston
"when you've got a much better language in C#"

That's subjective.

~~~
M8
It's not subjective. JS is only relevant due to ubiquity. Nobody transpiles to
C#. (well, except for Haxe - to nitpick, but it also transpiles to Java and
C++).

~~~
Nullabillity
Because people compile directly to CIR. See: VB.net, F#, Scala.net,
IronPython, IronRuby, etc.

~~~
M8
I meant C# is awesome so you just use it directly :).

------
nekitamo
Kind of lame how you can't use any of this, or even open it in Visual Studio,
unless you have Windows 8.1 installed.

~~~
ocdtrekkie
"It's kinda lame you need an OS made in the last six years at least to run
this."

Isn't this kind of like asking why Docker doesn't run on a Linux kernel from
2009? Windows 7 is six years old, don't be shocked some of Microsoft's newer
things might use newer platforms.

Guess it's good they're giving folks a free upgrade.

~~~
nekitamo
Microsoft's big selling point is backwards compatibility with their older OS.
Furthermore, according to this source Windows 7 still makes up for the vast
majority of Windows installs on consumer desktop computers:

[http://www.netmarketshare.com/operating-system-market-
share....](http://www.netmarketshare.com/operating-system-market-
share.aspx?qprid=10&qpcustomd=0)

So it's lame that they're releasing software that doesn't work for the
majority of their users, because they're trying to shove Windows 8 down
people's throats, which is quite frankly terrible user experience.

~~~
Stratoscope
That's not what backward compatibility means at all.

Of course new versions of Windows introduce new features! If you want to use
those new features, you need the new version.

Backward compatibility means that once they introduce a feature in one version
of Windows, they go to great lengths to keep that feature working in
subsequent versions.

It doesn't mean they have to backport every new feature into old versions of
the OS.

Also, Windows 8.1 doesn't have to be a terrible experience. Just get Start8
for $5, or whatever Start menu replacement you like, and you essentially have
a much-improved Windows 7.

~~~
frik
Win8.1 even with ClassicShell is just okay. Windows XP and 7 were great. I
understand for lite users Win8 is fine. But Win8 have like 5 different system
settings dialogs and pages and it's a total mess. It feels like Microsoft
either really doesn't get it or simply doesn't care that ModernUI doesn't work
& look that great on desktop. I will definitely wait how the Win10 launch
unfolds and how mature it is. If everything's goes wrong Win7 will last until
2022 when the official update-support ends.

~~~
ocdtrekkie
Well, they've obviously heavily revising their approach with Windows 10. But
Win 8's primary failing is it's learning curve. Once you know how to deal with
it, it's pretty massively superior to Windows 7. A lot of the easy ways to get
around in it are kinda hidden though.

