jacomyal / domino.js Goto Github PK
View Code? Open in Web Editor NEW[deprecated] A JavaScript cascading controller for fast interactive Web interfaces prototyping.
Home Page: https://jacomyal.github.io/domino.js
License: MIT License
[deprecated] A JavaScript cascading controller for fast interactive Web interfaces prototyping.
Home Page: https://jacomyal.github.io/domino.js
License: MIT License
I would like to declare custom structures, such as the data has to include some typed values associated to specified keys, but it can contain some other keys.
Here is an example of how I'd like to use that:
// Structure declaration:
domino.struct.add({
id: 'myStruct',
includes: true, // indicates that other keys can be used
struct: {
myKey: 'string'
}
});
// Some tests:
domino.struct.check('myStruct', {
myKey: 'myValue',
anotherKey: {
containing: 'anything'
}
}); // would return true
domino.struct.check('myStruct', {
myKey: 42
}); // would return false
Since there are now "fake" asynchronous methods available in scopes (dispatchEvent()
, request()
, ...), it might be more natural to use a method like update()
or set()
to update properties than directly adding them into the current scope. Especially since these properties are not in the scope until the user put them by himself to update their values.
For some objects, parameters are listed in the doc, and for some others they are missing:
Properties -> id
Hacks -> triggers, method, ...
Plus it would be cool to have a tree view summary like this:
An awesome enhancement of the workflow would be to have the possibility to declare domino modules directly from a template.
Two different ideas:
It would be great to have a reference on modules in the domino instance. This way you don't need to store them outside domino. Maybe you can give an ID to each module so you can find it like so:
domino.instances('foo').modules('bar')
Why not assume initial value missing is null when type: '?x'
?
It could avoid writing explicitly value: null
.
It would be great to have the possibility to override a toString
method for a property or a custom structure.
This could be useful at least to log updated values, and also for the templating features to come.
A module cannot call a service. When I have nothing special to do but I to make a request from a module, I declare a hack, and the module calls the hack, and the hack makes the request. This hack is trivial, like:
{triggers: ['requestMyService']
,method: function(e){
this.request('myService', e.data)
}
So I suggest a helper in the service, so that I could declare it like that:
{
id: 'myService'
,triggers: ['requestMyService']
...
}
The warning sent when a hack is trying to update a property that has already been updated during the same loop looks wrong (link):
'The property "' + k + '" is not a method nor a property.'
...because it sucks.
Following a discussion we had here, it would be nice to be able to document hacks
, properties
, services
, etc... such as it is possible to access these information from the console, through a method domInstance.help()
.
So the method could be used like this, for instance:
domInstance.help('properties/myProperty')
domInstance.help('hacks')
or domInstance.help('services')
domInstance.help('full')
I use a service with 'expect' and 'error' functions. I have a backend issue that makes the query fail and the 'expect' clause is not satisfied. My 'error' function correctly triggers, but the log says it is 'successfull'. Here is my service:
{
id: 'setCurrentWebEntityStatus'
,setter: 'statusValidation'
,data: function(settings){ return JSON.stringify({ //JSON RPC
'method' : HYPHE_API.WEBENTITY.SET_STATUS,
'params' : [
settings.shortcuts.webEntityId // web entity id
,settings.shortcuts.status // new status
],
})}
,path:'0.result'
,url: HYPHE_CONFIG.SERVER_ADDRESS, contentType: 'application/x-www-form-urlencoded', type: 'POST'
,expect: function(data){return data[0].code == 'success'}
,error: function(data){alert('Oops, an error occurred... \n\nThe server says:\n'+data)}
}
And here is the log:
[domino] Calling service "setCurrentWebEntityStatus". domino.js:1527
[domino] Service "setCurrentWebEntityStatus" successfull.
When you declare a new structure, if it embeds a structure that doesn't exist, you got the message: [domino.global] A structure requires a valid "structure" property describing the structure. It can be a valid structure or a function that test if an object matches the structure.
The stack trace gives you the line of the structure declaration, but it could be useful to know the key and structure involved.
e.g.:
domino.struct.add({
id: 'jacomyal',
struct: {
cruiseMode: 'unknownStruct'
}
});
In this case, you'd like to know that the key which causes error is cruiseMode
and the struct is 'unknownStruct'
, especially if you've got several complex structs.
The code domino.module.call(this);
should not be necessary: Since the controller will call the child module constructor, it can directly call it on a new domino.module
instead of a new empty object.
Of course, if domino.module.call(this);
is still there, the module must stay valid.
Hi,
When I call the following code in the success() method of a service :
this.dispatchEvent("event",{ foo : bar });
The event is dispatched, but not the data object.
Thanks,
Stéphane
Is it possible to list available (globally and locally) structures?
In a project I'm currently working on, I must load dynamically assets from my modules, and it's pretty painful, right now.
These assets cannot be referenced independantly in my domino controler, so since they are all lists, the property "lists"
represents them:
setTimeout
, for instance). So, I now when some assets are loaded (through the "listsUpdated"
event), but I am not sure yet that this is actually the piece I need. Indeed, some other modules created at the same time might have asked for some other assets, right?So, basically, what I suggest here is that for this kind of cases precisely, I would definitely enjoy to use a more classic, callback-based syntax to communicate from the module...
It would be useful. Something like :
{
id : 'save',
type : 'post',
url : '/uri',
contentType : 'application/json',
dataType : 'json',
data : function() {
var data = {
foo : "bar",
};
return JSON.stringify(data);
},
},
When manipulating the instance of domino, domInst.request('anyService')
, it returns the instance itself, but when calling .request()
inside functions (hacks, ...) it does not.
I propose a new feature to deal with a common issue. I often need to deal with properties that are lists of items. For instance I have a list of jobs to display, and I have a property called "jobsList" that is an array. Domino is not much adapted to dealing with this kind of properties. I'll just write here what I would like.
(...to be continued, sorry no more time today)
The MIME type has changed from https://raw.github.com, so it is no more possible to import JavaScript files directly from Github.
It would be nice to fix this, just by adding domino.min.js directly in the documentation branch.
Some applications use Ajax in a weird way, it could be nice to be able to modify some attributes of the XHR object be launching the call (making the before
feature more similar to the jQuery beforeSend
).
I just saw that a domino instance has a kill() method, but I can't see it in the documentation.
Thank you.
Bonjour
the domino instance method dispatchEvent for multiple events doesn't work as expected - i,e as described in the documentation:
domino.instance.dispatchEvent('event_type_a event_type_b');
Voila the workaround :
domino.instance.dispatchEvent('event_type_a').dispatchEvent('event_type_b');
In a hack method, instead of writing something like
this.log('[HACK] Do something');
, I suggest a native "description" key
description: 'Do something'
which would do the same.
"description
" could even be a function with event as param
triggers: ['doCoffee', 'doTea'],
description: function(e) {
return 'I am going to the kitchen to ' + e.type + ' for the breakfast';
}
When using an asynchronous action inside a hack, the "pseudo-methods" this.request()
, this.dispatchEvent()
etc are still existing, but of course are just useless.*
It might be better to throw errors when they are called lately.
It appears that using d
to name the domino instance is confusing since for a lot of people (especially the ones using d3.js), d
is a variable name for data.
It seems obvious that dom
should be avoided to. So, maybe controller
, control
or something like this could do the job.
It would be nice to have the current version at the beginning of the development file.
Here is the test case:
domino.utils.clone(document.createElement('div'));
When properties already have values and a module is created, it would be great to trigger the listeners. Even better: Triggering the events that have already been fired at least once would be awesome!
It would great if log
, warn
and die
were available in modules.
It might be good to have an access to the instance definition (properties, service, etc...), for example to easily generate forms from the properties. Also, it would be great to allow custom keys in properties / hacks / services / ...
There is a 'before' function. There could be an 'after' function, triggered however it is a success or a fail.
I would typically need it when I have to dispatch an event related to the fact that the query has been executed (however it succeeds or fails), like decrementing the count of pending queries. The 'before' function was very useful to increment this count.
It would be nice to log the server answer when the 'expect' clause fails, on a service. I don't think its the case currently.
Sometimes, executing some hacks or updating modules can be pretty expensive. It might be nice to be able to insert frames to avoid lag.
If this is done, it is important to deal with priorities as well, and to consider these priorities as dynamic.
This is a weird bug: When a service is called from inside domino (hacks, success callbacks, etc...), its success
callback is executed twice. And the same bug occurs when using setter
or events
as well.
Here is a test case:
var domInst = new domino({
hacks: [
{
triggers: 'myEvent1',
method: function() {
this.request({
service: 'myService'
});
}
},
{
triggers: 'myEvent2',
method: function() {
console.log('myEvent2 triggered');
}
}
],
services: {
myService: {
url: '/myService',
type: 'GET',
success: function() {
this.dispatchEvent('myEvent2');
}
}
}
});
domInst.dispatchEvent('myEvent1');
Here it is. Also, it looks like this bug is directly related to the last commit.
Edit: It is weirder than this, actually. The success
callback is executed one, but everything it does is used twice...
Sometimes there are some tooling functions that I'd like to be able to call from modules and hacks - but I do not want to put them in the global scope.
Adding a key in domino constructor configuration object to deal with these methods (that might have the read-only scope) would be really useful.
Would be nice to make it possible to catch services for one instance or globally. Here is an example (with d
a domino instance):
d.addAjaxHook('rpc', function(data) {
if ((data || {}).result !== 'Ok') {
this.warn('Unvalid response.');
return false;
} else
return true;
});
Then, when a service returns a data
object where data.result !== 'Ok'
, the related error
callback will be triggered instead of the success
callback, with the error message 'rpc'
.
I am working with RPC services, so I am using the expect
methods. And when the expect
fails, the error
callback is supposed to be triggered.
Instead, I have the following uncaught error:
Uncaught TypeError: Object #<Object> has no method 'xhr'
I think it comes from here.
Here are some cool features I would love to see implemented in domino.js:
It would be nice to have a setting to limit the self-loop depth (especially to detect inifinite loop).
Sometimes, several different events chains can be executed in parallele (when using before
in services, for instance). Then, the log can look like:
...
[myDomino] Iteration 1 (main loop)
[myDomino] -> Events: ["anEvent"]
[myDomino] Iteration 5 (main loop)
[myDomino] -> Events: ["anotherEvent"]
[myDomino] Iteration 6 (main loop)
[myDomino] -> Events: ["yetAnotherEvent"]
...
It might be useful to have each chain having an ID displayed, like this:
...
[myDomino] Iteration 1 (chain 2)
[myDomino] -> Events: ["anEvent"]
[myDomino] Iteration 5 (chain 1)
[myDomino] -> Events: ["anotherEvent"]
[myDomino] Iteration 6 (chain 1)
[myDomino] -> Events: ["yetAnotherEvent"]
...
When trying to make an ajax call to a URL with a port, the column is stripped and it fails.
Example: trying to send a post to:
http://fake.fr:6966/
Result: the post fails with this message:
POST http://fake.fr6966/
The issue comes from the loop at this point of the code:
https://github.com/jacomyal/domino.js/blob/master/src/domino.js#L579
(I tested that before, the URL is OK and after, it is corrupted).
Plugging a hack on a condition (like "when property COUNT goes over 42" or something) would just be awesome.
Since properties
, services
and shortcuts
have unique IDs and are not ordered, it would be better to declare them in hashes instead of arrays.
Shortcuts are often used as "dynamic properties". So, when properties are organized in different groups in the code (like "data", "interface", etc...), it is weird to have to group the shortcuts again, further in the configuration.
Since shortcuts are kind of properties, it might be nice to be able to declare them at the same place (in the "properties"
array).
Currently when I get a type error, it looks like this:
Uncaught Error: [domino] Property "accounts": Type not valid
I would greatly appreciate something like:
expected: "?(array)" was "?(object)"
Or even the wrapped object like:
Uncaught Error: [domino] Property "accounts": Type not valid (expected: "?(array)" was "?(object)") ▶Object {blabla:...}
Say we have d
an instance of domino, with serv1
and serv2
two services.
The following code works well ("Yay!"
show up in the console):
d.request('serv1', {
success: function() {
console.log('Yay!');
}
});
But if I call two services in the same call, I have no log, the success
callback is never called:
d.request(['serv1', 'serv2'], {
success: function() {
console.log('Yay!');
}
});
In _mainLoop
, it is possible to use a "force"
flag to force properties to trigger descending events, even if the new value is not different than the old one. And that's great.
Unfortunately, there is currently just no way to use that flag... That would be great to be able to use this flag exactly as the clone
flag:
Since domino.js already has its own "typing engine", it might be nice to be able to specify in services definition an object to constraint the input object.
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.