Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
A simple AMD insipired module system for keeping your codebase organized. Supports modern browsers (IE9+) and Node.js. Palikka is heavily influenced by RequireJS and modulejs libraries and you should definitely check them out too.
First of all, include Palikka somewhere on your site (before any code that requires Palikka).
You can define new modules using the .define()
method.
Palikka
.define('c', ['a', 'b'], function (req) {
var a = req('a');
var b = req('b');
console.log(a + ' ' + b + '!'); // "Hello world!"
return a + b;
})
.define('a', 'Hello')
.define('b', 'world');
Also you can just .require()
modules if there is no need to define a new module.
Palikka.require(['a', 'b'], function (req) {
var a = req('a');
var b = req('b');
console.log(a + ' ' + b + '!'); // "Hello world!"
return a + b;
});
Sometimes a module's initiation needs to be delayed.
Palikka.define('d', ['a', 'b'], function (req, defer) {
var a = req('a');
var b = req('b');
var done = defer();
window.setTimeout(function () {
done(a + ' another ' + b + '!');
}, 1000);
});
When you start having tens or hundreds of modules it's handy to check the status of the modules with .getLog()
method. Especially helpful for quick debugging.
console.log(Palikka.getLog());
You can also fetch the current data of all modules with .getData()
method.
var modules = Palikka.getData();
Palikka
is also constructor function that creates a new independent module system instance when initiated with new
keyword.
var moduleSystem = new Palikka();
var anotherModuleSystem = new Palikka();
moduleSystem
.define('a', 'Hello')
.define('b', 'world')
.require(['a', 'b'], function (r) {
console.log(r('a') + ' ' + r('b') + !); // Hello world!
});
anotherModuleSystem
.define('a', 'Hello')
.define('b', 'human')
.require(['a', 'b'], function (r) {
console.log(r('a') + ' ' + r('b') + !); // Hello human!
});
Define one or more modules. After a module is defined another module cannot be defined with the same id. Undefining a module is not possible either. If you try to define a module with an existing module id Palikka will silently ignore the define command. Palikka does not support defining circular dependencies, but it does detect them and throws an error when it sniffs one.
.define( ids, [ dependencies ], [ value ] )
[]
.undefined
.Returns — Palikka
If .define()
is called on a Palikka instance the instance is returned. Otherwise if the method is called on the Palikka
constructor function then Palikka
constructor is returned.
Examples
// Define a module with a factory function.
Palikka.define('foo', function () {
return 'foo';
});
// Define a module with a direct value.
Palikka.define('bar', 'bar');
// Define a module with dependencies.
Palikka.define('foobar', ['foo', 'bar'], function (req) {
var foo = req('foo');
var bar = req('bar');
return foo + bar;
});
// Define a module using deferred initiation.
Palikka.define('delayed', function (req, defer) {
var done = defer();
setTimeout(function () {
done('I am delayed...');
}, 2000);
});
// Define multiple modules at once.
// Handy for importing third party libraries.
var obj = {a: 'I am A', b: 'I am B'};
Palikka.define(['a', 'b'], function (req, defer, id) {
return obj[id];
});
Require one or more modules and do stuff after they have loaded.
.require( ids, callback )
Returns — Palikka
If .require()
is called on a Palikka instance the instance is returned. Otherwise if the method is called on the Palikka
constructor function then Palikka
constructor is returned.
Examples
Palikka
.define('a', 'foo')
.define('b', 'bar')
.require(['a', 'b'], function (req) {
var a = req('a');
var b = req('b');
alert(a + b); // "foobar"
});
Returns a tidy list of all the currently defined modules and their dependencies in the exact order they were defined. The list also indicates each module's current state — undefined ( )
, defined (-)
or ready (v)
.
.getLog( [ ids ] )
Returns — String
Examples
Palikka
.define('a')
.define('b')
.define('c', ['a', 'b'], {})
.define('d', ['c', 'x'], {});
// Log a single module.
console.log(Palikka.getLog('a'));
// (v) a
// Log multiple modules.
console.log(Palikka.getLog(['a', 'c']));
// (v) a
// (v) c
// (v) a
// (v) b
// Log all modules.
console.log(Palikka.getLog());
// (v) a
// (v) b
// (v) c
// (v) a
// (v) b
// (-) d
// (v) c
// ( ) x
Returns an object containing some helpful information about all the currently defined modules.
Returns — Object
Examples
Palikka
.define('a', 'foo')
.define('b', 'a', 'bar');
var data = Palikka.getData();
// {
// a: {
// id: "a",
// order: 1,
// dependencies: [],
// ready: true,
// value: 'foo'
// },
// b: {
// id: "b",
// order: 2,
// dependencies: ['a'],
// ready: true,
// value: 'bar'
// }
// }
Copyright © 2016 Niklas Rämö. Licensed under the MIT license.
FAQs
A tiny module system.
The npm package palikka receives a total of 5 weekly downloads. As such, palikka popularity was classified as not popular.
We found that palikka demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.