Subjects.ts
Subjects.ts is very simple typescript utilities using Subject pattern (Observer and Observable) based on TSX (JSX).
Main goal of this project is to help web application development without learning huge front end frameworks.
Install
npm install --save subjects-ts
Examples
See example.tsx and example.html for live examples.
Minimal example of SubjectObject
;let sub = SubjectsSubjectObject<string>;;console;sub;sub;;console;
Minimal example of SubjectArray
;let sa = <string>;sa;let mapped = sa;mapped;
Browser Example
example.tsx
import * as Subjects from 'subjects-ts'; public Subject = SubjectsSubjectObject<string>; public Done = SubjectsSubjectObject<string>; public { Object; } let todos = <Todo>;todos;todos;todos; documentbody; let <void> ; { todos; await ; todos; await ; todos; await ; todos; await ; todos; await ; todos; await ;};
example.html
tsconfig.json
API
-
ISubjectObject.ts, SubjectObject.ts
- ### (value?: any): any; () to get value and (value) to notify callback (observer).
- ### IsSubject: boolean; Whether this object is ISubjectObject or not. (as transpiled javascript won't have interface type)
- ### AddCallback: (callback: Function) => void; Add callback (observer) to this object.
- ### RemoveCallback: (callback: Function) => void; Remove callback (observer) from this object.
-
SubjectArray.ts
- ### Get(index: number): T Array[index]
- ### Set(index: number, item: T): void Array[index] = item
- ### Remove(index: number): void Array.slice(index, 1)
- ### Map(func: (item: T) => any): SubjectArray Array.map(func)
- ### Push(item: T): void Array.push(item)
- ### ForEach(func: (item: T) => void): void Array.forEach(func)
- ### Clear(): void Array = []
- ### AddCallbackToOriginalSubjectArray(methodName: MethodName, func: Function): void Register callback (observer) to original SubjectArray where Map() occurred.
- ### ExecuteMapFunction(item: T): any Execute map function which created this SubjectArray.
-
SubjectProcessor.ts
- ### SubjectProcessor()
This is example jsx factory function you can specify as "jsxFactory" in tsConfig.json."jsxFactory": "Subjects.SubjectProcessor"
- ### SubjectProcessor()
This is example jsx factory function you can specify as "jsxFactory" in tsConfig.json.
Misc
I'll add more functionalities and fix bugs as I use but please feel free to contribute :)