2.0.56 • Published 13 hours ago

sufficient v2.0.56

Weekly downloads
4
License
MIT, Anti-996
Repository
github
Last release
13 hours ago

Sufficient

An MVC framework with scheduling.

This framework came into being as a result of Juxtapose, which provides the means to create an application's view. The corresponding model will always be bespoke, so there are no means to create it either here or in Juxtapose. That leaves the controller, which is implemented here. The reason that Sufficient is called an MVC framework is that the more or less prescriptive guidelines for putting an application together using these approaches are spelled out in what follows.

In summary, all that is to be found here is a scheduler and a modified controller, together with prescriptions which you should follow in order to make use of them. The scheduler will be needed if you want to write an application that encompasses asynchronous behaviour such as accessing the file system, or has concurrent functionality.

Installation

You can install Sufficient with npm:

npm install sufficient

You can also clone the repository with Git...

git clone https://github.com/djalbat/sufficient.git

...and then install the dependencies with npm from within the project's root directory:

npm install

Usage

The basic idea is to create a view and a model and to pass these, together with a scheduler and a createMethods() function to make use of them all, to the assignMethods() method of the controller singleton. Only once these methods have been assigned to the controller is the view attached to the browser's DOM:

import { Scheduler, controller } from "sufficient";

const scheduler = Scheduler.fromNothing(),
      model = new Model(),
      view =

        <View />

      ;

controller.assignMethods(createMethods, scheduler, model, view);

const body = new Body();

body.mount(view);

Invoking controller methods

Aside from being imported above, the controller should normally only be imported, and therefore its methods only invoked, from within the view classes. Furthermore, its methods should be invoked only in response to user events. Typically:

class ResetPasswordButton extends Element {
  clickHandler(event, element) {
    controller.resetPassword();
  }

  ...

  didMount() {
    this.onClick(this.clickHandler, this);
  }

  willUnmount() {
    this.offClick(this.clickHandler, this);
  }

  ...
}

Here the clickHandler() method will only be invoked in response to user interaction and this can only happen once the view has been attached to the DOM. And, in turn, this happens only after all of the requisite methods have been attached to the controller object as described above.

Creating tasks

It is the job of controller methods to be available to the view as well as to create the tasks that manage the relationship between model and view or to carry out any other application functionality. Closure gives them access to the scheduler, the model and the view, with the aforementioned functionality typically being implemented by helper methods:

import { Task } from "sufficient";

import setPasswordHelper from "./helper/setPassword";

function createMethods(scheduler, model, view) {
  function setPassword(password) {
    const done = () => {},  ///
          setPasswordTask = new Task(setPasswordHelper, model, view, done);

    scheduler.addTaskToQueue(setPasswordTask);
  }

  return ({
    resetPassword
  });
}

Note the vacuous done() callback. The Task class constructor expects the last of its arguments to be a callback and will invoke it once the task has been executed, therefore such a method must be passed. Alternatively, a done argument could have been included in the setPassword(...) method's arguments and simply passed on. Here the assumption is that the caller requires no notification via a callback that the task has been executed.

Now the createMethods() function can export a setPassword() function that instantiates the requisite task and schedules it:

import SetPasswordTask from "./task/setPassword";

function createMethods(scheduler, model, view) {
  function setPassword(password) {
    const setPasswordTask = new SetPasswordTask(model, view, done);

    scheduler.addTaskToQueue(setPasswordTask);
  }

  return ({
    setPassword
  });
}

The tasks and scheduler are agnostic to method arguments. In the above examples the references to the model and view have been utilised but any number of arguments can be passed to the task constructor. A look at the implementation of the Task class gashould convince.

Building

Automation is done with npm scripts, have a look at the package.json file. The pertinent commands are:

npm run build-debug
npm run watch-debug

Contact

  • james.smith@djalbat.com
2.0.56

13 hours ago

2.0.55

1 month ago

2.0.54

1 month ago

2.0.51

1 month ago

2.0.52

1 month ago

2.0.48

1 month ago

2.0.49

1 month ago

2.0.47

3 months ago

2.0.46

3 months ago

2.0.44

4 months ago

2.0.45

4 months ago

2.0.42

4 months ago

2.0.43

4 months ago

2.0.41

5 months ago

2.0.40

7 months ago

2.0.37

8 months ago

2.0.38

8 months ago

2.0.39

8 months ago

2.0.36

1 year ago

2.0.33

1 year ago

2.0.34

1 year ago

2.0.31

2 years ago

2.0.32

2 years ago

2.0.28

2 years ago

2.0.29

2 years ago

2.0.30

2 years ago

2.0.26

2 years ago

2.0.27

2 years ago

2.0.15

3 years ago

2.0.16

3 years ago

2.0.13

3 years ago

2.0.14

3 years ago

2.0.11

3 years ago

2.0.12

3 years ago

2.0.19

2 years ago

2.0.17

3 years ago

2.0.18

2 years ago

2.0.24

2 years ago

2.0.25

2 years ago

2.0.22

2 years ago

2.0.23

2 years ago

2.0.20

2 years ago

2.0.21

2 years ago

2.0.10

3 years ago

2.0.9

3 years ago

2.0.8

3 years ago

2.0.7

3 years ago

2.0.6

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.2.10

3 years ago

1.2.9

3 years ago

1.2.8

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.1.32

4 years ago

1.1.31

4 years ago

1.1.30

4 years ago

1.1.28

4 years ago

1.1.27

4 years ago

1.1.26

4 years ago

1.1.25

4 years ago

1.1.24

4 years ago

1.1.23

4 years ago

1.1.22

4 years ago

1.1.21

4 years ago

1.1.20

4 years ago

1.1.19

4 years ago

1.1.18

4 years ago

1.1.17

4 years ago

1.1.16

4 years ago

1.1.15

4 years ago

1.1.14

4 years ago

1.1.13

5 years ago

1.1.12

6 years ago

1.1.10

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.24

6 years ago

1.0.23

7 years ago

1.0.22

7 years ago

1.0.21

7 years ago

1.0.20

7 years ago

1.0.19

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.3

7 years ago