Git Product home page Git Product logo

sayori's Introduction

setamo-arts.tumblr.com

sayori's People

Contributors

pixeltopic avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

sayori's Issues

Update route matching algorithm

Currently, the route matching does not handle duplicate aliases well in subroutes due to the matching algorithm.

Assume there is a route root

Two subroutes A and B are added to root as subcommands in this order. They both have the same aliases, foo.
However, B's subroute has another subroute (let's call it C). C has an alias bar.

A message comes in: foo bar

Because of the current match algorithm, route A will be found first, and route B, which has the same alias, will not be considered.

After the algorithm rewrite, the "greedy" aspect of this algorithm will be lessened, but not eliminated. The algorithm will instead select the newest added route B because

  1. It is newer
  2. It is a better match (will match foo bar instead of just foo)

Custom Middleware Support

Sayori currently supports preset filters. However, it should also support filters that accept custom callbacks - "middlewares".

Each Command or Event can have 0 or more custom middlewares appended using Builder. These middlewares are run sequentially after Filter is processed.

A middleware function signature comes in the form of func(Context) error.

Subcommands

Tentative. If a user wants to implement a subcommand, they just need to specify an alias with a space in it:

rootcommand subcommand

The Match function should account for this and in makeCommand it should do strings.Fields to split the command and subcommand by whitespace before storing them in an ordered string slice within Context.

Resolve interface func should be optional

Right now Resolve is forced to be implemented after Handle runs. In order to make this less opinionated, Resolve should be an optional function that will be checked after handle is run using an interface type assertion. If Resolve is not implemented, any errors produced by Handle will be subsumed.

Expose Route removal from Router

Currently when a Route is added, there is no way to remove them. New fix adds a func() return type which will remove the handler when called.

Reduce Route mutability after adding it into Router

Routes are added into the router using a pointer when they should be passed by value. This would mean that attempting to change aliases, middlewares, and subroutes will remain consistent throughout the Route lifetime. However, this will not protect against:

  • any future fields in Route that use a map
  • the handler type's internal state from being changed
  • the prefixer's internal state from being changed

Remove pointer in Prefix within Context

This was mistakenly added when I was working on the subroute searching algorithm because I thought I had to skip the prefix trimming for every route after the root route.

This should be unnecessary - a Prefixer (if nil) will return an empty string. If a given Prefixer also returns an empty string, we don't need to differentiate this because they are functionally the same.

Finish README in v2

v2 lacks a detailed README. When this is complete an initial release can be cut for v2.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.