divnix / POP

Pure Object Prototypes
MIT License
20 stars 1 forks source link

Add extenders API #3

Closed Pacman99 closed 1 year ago

Pacman99 commented 2 years ago

Extenders are functions that are part of the pop that extend the pop in a specific way when called.

For example:

row = pop {
  defaults.panels = [ ];
  extenders.addPannel = panel: self: super: {
    panels = super.panels ++ [ panel ];
  };
}
(row.addPanel {}).addPanel {}

Would return:

{ __meta__ = ...; panels = [ {} {} ]; addPanel = <lambda>; }

I also added an unpop function to reside within a pop, so you can do p.__unpop__ instead of lib.unpop p.

TODO

fare commented 2 years ago

I like the general idea, but there are many small issues I'd like to discuss.

Pacman99 commented 2 years ago

rebased and updated with your feedback, I still have to write tests for these changes

Pacman99 commented 1 year ago

Existing code allows for this already, so no need for this

pop {
  defaults.value = 1;
  extension = self: super: {
    incValue = num: extendPop self (self: super: { value = super.value + num; });
  };
}