fabien-d / sandboxed-js Goto Github PK
View Code? Open in Web Editor NEWJavaScript specs for a sandboxed web
JavaScript specs for a sandboxed web
This is just a draft of an idea, curious what people think about it
Most people have seen or should see Nicholas Zakas' talk on building "Scalable JavaScript Application Architecture" (slides, video).
The sandbox concept (interface for each module to promote loose coupling) was something new for me and has changed the way I code. It has helped me organize my code for my own projects and thought maybe it could benefit all developers.
Too often I've had to write custom modules or alter existing modules to remove jQuery references because I wasn't using the framework in my project. This got me thinking, how great would it be if modules extracted references to third party libraries and hid them behind a sandbox. They could then be altered without touching the core code. This would allow a module to be based on any framework without writing module.jquery.js
, module.mootools.js
, module.native.js
and so on.
There are way more pros/cons, this is just a draft.
Here's a very basic example showing ONLY the concept:
// jQuery is a must for it to work
var el = $( '#element' );
el.addClass( 'super-awesome-class' );
var el = sandbox.dom.find( '#element' );
sandbox.dom.addClass( el, 'super-awesome-class' );
sandbox.dom.find = function ( selector ) {
return document.querySelector( selector );
};
sandbox.dom.addClass = function ( el, str ) {
el.classList.add( str );
};
// would include a jQuery adapter
sandbox.dom.find = function ( selector ) {
return $( selector );
};
sandbox.dom.addClass = function ( el, str ) {
el.addClass( str );
};
This would allow developers to create their own sandbox(es) and use any modules that were developed following the specs without tweaking any code.
Specs would have to be written and an API would have to be defined. This would include common functionality that would best be separated from the core code of modules (essentially everything that is handled via third party library/framework). A few examples could include:
dom.find
dom.findAll
dom.addClass
dom.removeClass
dom.toggleClass
event.bind
or events.on
event.unbind
or events.off
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.