Skip to content

Instantly share code, notes, and snippets.

View Sean-Bradley's full-sized avatar
📰
https://sbcode.net

SBCODE Sean-Bradley

📰
https://sbcode.net
View GitHub Profile
class Light:
"""The Reciever"""
def turn_on(self):
print("Light turned ON")
def turn_off(self):
print("Light turned OFF")
if __name__ == "__main__":
# The Client is the main python app
# The Light is the Reciever
LIGHT = Light()
# Create Commands
SWITCH_ON = SwitchOnCommand(LIGHT)
SWITCH_OFF = SwitchOffCommand(LIGHT)
class Slider(IUndoRedo):
"""The Invoker Class"""
def __init__(self):
self._commands = {}
self._history = [(0.0, "OFF", ())] # A default setting of OFF
self._history_position = 0 # The position that is used for UNDO/REDO
...
@property
def history(self):
"""Return all records in the History list"""
return self._history
def undo(self):
"""Undo a command if there is a command that can be undone.
Update the history psoition so that further UNDOs or REDOs
point to the correct index"""
if self._history_position > 0:
def execute(self, command_name, *args):
"""Execute a pre defined command and log in history"""
if command_name in self._commands.keys():
self._history_position += 1
self._commands[command_name].execute(args)
if len(self._history) == self._history_position:
# This is a new event in hisory
self._history.append((time.time(), command_name, args))
else:
# This occurs if there was one of more UNDOs and then a new
class IUndoRedo(metaclass=ABCMeta):
"""The Undo Redo interface"""
@abstractstaticmethod
def history():
"""the history of the states"""
@abstractstaticmethod
def undo():
"""for undoing the hsitory of the states"""
class IProtoType(metaclass=ABCMeta):
"""interface with clone method"""
@abstractstaticmethod
def clone():
"""The clone, deep or shallow, is up to how you
want implement the details in your concrete class?"""
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
"outDir": "dist",
"sourceMap": true
},
"files": [
{
"openapi": "3.0.0",
"info": {
"version": "1.0.0",
"title": "The Title of your project",
"description": "A description of your project",
"license": {
"name": "MIT",
"url": "https://opensource.org/licenses/MIT"
}
import express from 'express'
import Router from './router'
import swaggerUi from 'swagger-ui-express'
import * as swaggerDocument from './swagger.json'
import * as bodyParser from 'body-parser'
class App {
private httpServer: any
constructor() {