Hacker Newsnew | past | comments | ask | show | jobs | submit | gliechtenstein's commentslogin

You guys should check out https://www.celljs.org if you like this type of approach


> That's more human readable, but also slightly inconsequent - you wouldn't be able to validate such a template with json schema for example.

Could you elaborate?


Just to use the json-schema example - because the transform uses templating syntax inside strings, I wouldn't be able to write a json-schema to check if a given transform object is valid or not, which can quickly become an issue for growing sizes of transforms.


Thanks! I actually built this library for my own usage (Jasonette) and decided to open source it because I realized it can be powerful for all kinds of other purposes.

In essence ST.js is a finite state machine implemented purely in JSON. So I can imagine it being used for things I haven't thought of, which is why I open sourced it. Would be really cool.

Please feel free to reach out at ethan.gliechtenstein[at]gmail thanks!


Hi, my name is Ethan. I'm the creator.

I thought I would provide some context on why I wrote this library, and how I'm using this right now. So here it goes:

Other than ST.js, I also work on another open source project called Jasonette (https://www.jasonette.com), which lets you write an entire native iOS/Android app in nothing but JSON markup.

And when you can express the entire app logic--from model to view to controller--in JSON, you can split them up whichever way you want and load them from anywhere (from a file, from cache, from a remote server, or from local memory).

But the biggest benefit of all is: you can load an entire ios/android native app from the server in realtime, just like how web browsers load HTML/JS/CSS in realtime.

When working on Jasonette, implementing model and view was relatively simple. For model it's natural since JSON is all about describing data. For view i just needed to come up with a syntax to describe layouts and all the standard mobile UI components in JSON.

However the biggest challenge was how do i actually describe functions in JSON. Without a function, it's just a mockup and won't really do anything meaningful.

Which brings us to ST.js.

When you think about what a function is, it takes one value and turns it into another. So basically what I needed to do was build something that will take one JSON, and turn it into another JSON, but most importantly I would have to do it using JSON. Basically I needed to implement a finite state machine in purely JSON.

And this is what templates do. So I set out to build a JSON template engine that turns one JSON into another using a template which itself is written in JSON.

What's really cool about this is, since the template is JSON (As far as I know there doesn't exist any prior art that uses JSON as a template, otherwise I would have used it instead), it has all the benefits of the JSON format itself:

1. You can store it anywhere (Most DBMS nowadays support JSON natively)

2. You can send it over the Internet

3. You can compose them easily

4. You can validate them using JSON schema

5. etc.

To use a more specific example, I use ST.js in both Android and iOS versions of Jasonette as the template engine. And a JSON template is absolutely necessary in this case.

For example, if I want to take a piece of device-generated data and render it, I need to be able to somehow parse it client-side (can't send it back to server to re-generate a JSON) http://docs.jasonette.com/templates/#3-device-api-generated-...

This also applies to many cases where the client-side data contains privacy-sensitive data. The only way to dynamically parse something that happens on the client side is by writing the template itself in JSON and sending it over as data.

Anyway, I hope you guys take a look at the examples on the homepage to get a glimpse of what makes ST.js powerful. Each example is almost its own library, except that you don't need a separate library for those purposes since all you're dealing with is JSON.


The project is interesting... But I don't understand your point about JSON vs JS.

1. You can store JS anywhere (all DBMS support text).

2. You can send it over the Internet... Like everything else nowadays.

3. You can compose JS easily.

4. You can validate JS using linters.

5. etc.

Besides... Aren't you only disguising functions in strings? You can eval strings anyway.


This is cool, nice job. And thanks for open sourcing the Jasonette code.

I've done something similar to ST out of the same frustrations at work, but my use case was way more specific, and you took it way farther with better execution.


So Jasonette functions are just about transforming the model, all in a reactive way? Like view->events->transform model->view?


It can transform anything that's written in JSON, which means both model and view and anything else.

One of the use cases for ST.js in Jasonette is dynamic client-side rendering, where it takes dynamic data and renders it against the template, after which it becomes native components.

Another use case is implementing actual functional programming. This one is not as straight-forward since it involves maintaining another separate state machine for function call stack. But this is also achieved using ST templates. Here's a blog post that talks about it in detail http://blog.jasonette.com/2017/02/15/functional-programming-... but it's a bit involved.

Also Jasonette has something called mixins, which you probably can guess based on its name. It lets you mix in JSON objects into another, so that you can make the app modular. That's also achieved internally using ST.

Overall, I believe even I'm just scratching the surface of what this can do, which is why I decided to take some time to clean things up and prepare and open it up as its own repo, because I think there's tons of other things that can be done by taking advantage of the fact that all that's happening is:

JSON A + JSON B = JSON C

Hope this makes sense!


> Another use case is implementing actual functional programming

I remember our chat 8 months earlier on Reddit about this: https://www.reddit.com/r/functionalprogramming/comments/5ufm...

Yeah. You're still aiming for "functional programs encoded as (essentially) s-expressions but written in JS-Object-Notation (JSON) instead of LISPy parens". And that's still fine if you see that as a major leap forward. Not sure about the audience, those who want to "functionally program a mobile quasi-native APP that can self-update from a server" and know what the "functionally program" part means, wouldn't they reach for JS via React Native? Same selling points implicit already. Is it for those who never programmed but are expected to declaratively express functional idioms in your JSON notation without needing to install all sorts of dev tools and SDKs? Not entirely implausible at all I guess. Curious to see who will end up as your target audience. =)


Creator here. Yup, in fact you can check out something like that here https://github.com/SelectTransform/JSONQL

Basically you can send the JSON template over JSON to the server, and let the server transform the raw data using the template before returning.

The most important benefit here is that, since everything can be expressed in JSON, it can be stored or transmitted over the Internet, which enables interesting cases like this.


Hey guys I know this post will be one of the most meta things to post here and probably a lot of people will say "what's the point?" but I thought it was cool so thought I would share.

For background, I am working on a JS library called cell.js (https://www.celljs.org), which turns a JSON object into a dynamic web app.

Anyway, this particular app (HTML to JSON to DOM) takes any HTML, parses it into JSON, and feeds it to cell.js, which then turns it back to DOM again. I built it because sometimes I just want to take an existing HTML and transform it to JSON, so I can turn any existing website into cell, and it works pretty well for that purpose.

You can try copy and pasting any website HTML into it to see the effect, as shown at https://github.com/gliechtenstein/HTML2JSON2DOM. Hope you find it cool as well!


Pretty cool!


Thanks! :)


This looks awesome! I believe being able to express an entire app logic as data can be super powerful.

BTW shameless plug: If you're interested in this type of ideas, please also check out Jasonette (an open source project I'm working on) Just like this project uses "list" to describe an app, Jasonette uses JSON to describe an app. https://www.jasonette.com


Thanks! I'll be honest, cell is only a couple of days old, and I myself can't say what The best practices are.

And this is by design because the goal was to create complexity out of simplicity.

I believe this bottom up approach can be much more scalable in the long run than some frameworks that dictate every single detail you need to implement, because all organisms are basically built that way (cells make up body) and they seem to be working fine.

Personally the more I use this the more I find creative ways of using it, which is the beauty.

But I also do realize sometimes it's good to have some sort of "best practice" structure and I think people will figure it out eventually.

TLDR: I think you should be able to build all kinds of sophisticated apps with it because I believe emergence is the best way to construct something. if that's not the case, that doesn't mean the framework is a failure but just needs some tuning, which I believe is totally possible just because the library is so minimal. So please feel free to play with it and share if you run into trouble, we can evolve cell just like cells evolve in the real world.


I hope these are enough (They're on the homepage as well if you want a more readable version):

How it has a different architecture: https://github.com/intercellular/cell#so-how-does-it-work-ex...

What these architectural decisions mean and how they make a difference https://github.com/intercellular/cell#how-does-this-make-a-d...


Sorry about that!

I'm using some in-house library I built myself to run the webpage but hadn't realized it fails on an IE. Will fix it!


Cool! It's just a guess but if you are by chance counting on a promise to load content, WP needs a polyfill.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: