Awesome, but I honestly don’t like those multiple parameters like that. I prefer a one object for params:
LocalNotify.now({
text: "Boom!",
text2: "Just like that",
type: "payload",
bool: true
})
As you can see idk what to name those properties because I can’t tell, so if you could make it where the object has to have specific name properties then that’d be more awesome and I don’t have to remember what order which parameter goes etc.
Plus we get to take advantage of destructuring in ES6 and more.
Above I chose text
and text2
because I have no idea what those paremeters stand for, same thing for type
I just thought it’d be a type. Same thing for the last boolean not sure what that parameter sets. So I think you get my point however.
Now for the later
method you can just have the first parameter be a timeout, and the rest for options:
LocalNotify.later(4, {
text : "Finally!",
text2: "4 seconds is a long time",
type: "hmm?",
bool: true
});
See now payload
is now hmm?
so I’m assuming its not even a type
Or just have all parameters in the object:
LocalNotify.later({
timeout: 4,
text : "Finally!",
text2: "4 seconds is a long time",
type: "hmm?",
bool: true
});
For the event handler:
Keep the onReceievedMessage
property as a event handler but also have a Promise
based one:
LocalNotify.receievedMessage.then(function(payload) {
console.log ("Recieved Local Notification: " + payload);
});
Where receivedMessage
is a Promise
. Again Promises is not just about style of code, and too long for me to explain here, but on the Fuse team side I’m sure it can be done